40 lines
927 B
Ruby
40 lines
927 B
Ruby
# app/models/configuracao.rb
|
|
class Configuracao < ApplicationRecord
|
|
TIPOS = %w[entrega retirada bonus desconto].freeze
|
|
|
|
enum tipo: { entrega: 0, retirada: 1, bonus: 2, desconto: 3 }
|
|
|
|
validates :tipo, presence: true, uniqueness: true
|
|
validates :valor, presence: true,
|
|
numericality: { greater_than_or_equal_to: 0 }
|
|
|
|
LABELS = {
|
|
'entrega' => 'Entrega Normal',
|
|
'retirada' => 'Retirada',
|
|
'bonus' => 'Bônus',
|
|
'desconto' => 'Desconto'
|
|
}.freeze
|
|
|
|
ICONES = {
|
|
'entrega' => '🚚',
|
|
'retirada' => '📦',
|
|
'bonus' => '⭐',
|
|
'desconto' => '🔻'
|
|
}.freeze
|
|
|
|
def tipo_label
|
|
LABELS[tipo] || tipo.humanize
|
|
end
|
|
|
|
def icone
|
|
ICONES[tipo] || '💰'
|
|
end
|
|
|
|
# Retorna um hash { entrega: 10.50, retirada: 8.00, bonus: 5.00, desconto: 2.00 }
|
|
def self.mapa_de_precos
|
|
all.each_with_object({}) do |c, h|
|
|
h[c.tipo.to_sym] = c.valor.to_f
|
|
end
|
|
end
|
|
end
|