2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-06-09 11:48:30 +02:00
|
|
|
class Logic::Constant < Logic::Term
|
|
|
|
attr_reader :value
|
|
|
|
|
2022-07-06 09:44:54 +02:00
|
|
|
def initialize(value)
|
2022-06-09 11:48:30 +02:00
|
|
|
@value = value
|
|
|
|
end
|
|
|
|
|
2023-01-04 11:10:10 +01:00
|
|
|
def sources
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
2022-06-09 11:48:30 +02:00
|
|
|
def compute(_champs = nil) = @value
|
|
|
|
|
2022-09-26 21:21:55 +02:00
|
|
|
def to_s(_type_de_champs = [])
|
2022-06-27 12:32:00 +02:00
|
|
|
case @value
|
|
|
|
when TrueClass
|
|
|
|
I18n.t('utils.yes')
|
|
|
|
when FalseClass
|
|
|
|
I18n.t('utils.no')
|
2023-07-28 10:18:39 +02:00
|
|
|
when Champs::DropDownListChamp::OTHER
|
|
|
|
'Autre'
|
2022-06-27 12:32:00 +02:00
|
|
|
else
|
|
|
|
@value.to_s
|
|
|
|
end
|
|
|
|
end
|
2022-06-09 11:48:30 +02:00
|
|
|
|
2022-09-26 21:07:43 +02:00
|
|
|
def type(_type_de_champs = [])
|
2022-06-09 11:48:30 +02:00
|
|
|
case @value
|
|
|
|
when TrueClass, FalseClass
|
|
|
|
:boolean
|
|
|
|
when Integer, Float
|
|
|
|
:number
|
|
|
|
else
|
|
|
|
@value.class.name.downcase.to_sym
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-09-26 21:11:43 +02:00
|
|
|
def errors(_type_de_champs = nil) = []
|
2022-06-09 11:48:30 +02:00
|
|
|
|
|
|
|
def to_h
|
|
|
|
{
|
2022-07-05 14:47:32 +02:00
|
|
|
"term" => self.class.name,
|
2022-07-06 09:44:54 +02:00
|
|
|
"value" => @value
|
2022-06-09 11:48:30 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.from_h(h)
|
2022-07-06 09:44:54 +02:00
|
|
|
self.new(h['value'])
|
2022-06-09 11:48:30 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def ==(other)
|
|
|
|
self.class == other.class && @value == other.value
|
|
|
|
end
|
|
|
|
end
|