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
|
|
|
|
|
|
|
|
def compute(_champs = nil) = @value
|
|
|
|
|
2022-06-27 12:32:00 +02:00
|
|
|
def to_s
|
|
|
|
case @value
|
|
|
|
when TrueClass
|
|
|
|
I18n.t('utils.yes')
|
|
|
|
when FalseClass
|
|
|
|
I18n.t('utils.no')
|
|
|
|
else
|
|
|
|
@value.to_s
|
|
|
|
end
|
|
|
|
end
|
2022-06-09 11:48:30 +02:00
|
|
|
|
|
|
|
def type
|
|
|
|
case @value
|
|
|
|
when TrueClass, FalseClass
|
|
|
|
:boolean
|
|
|
|
when Integer, Float
|
|
|
|
:number
|
|
|
|
else
|
|
|
|
@value.class.name.downcase.to_sym
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def errors(_stable_ids = nil) = []
|
|
|
|
|
|
|
|
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
|