fix(condition): make condition work with decimal

This commit is contained in:
Eric Leroy-Terquem 2023-11-08 12:07:21 +01:00
parent 1b4010205a
commit 22eadafe07

View file

@ -48,9 +48,10 @@ class ConditionForm
return empty if value.blank? return empty if value.blank?
if left_type == :number if left_type == :number
# in this special case, we try to cast as Integer # in this special case, we try to cast as Float, then Integer
# but it can still be a previous string value or a mistap # but it can still be a previous string value or a mistap
number = Integer(value) rescue nil number = parse_to_number(value)
return constant(number) if number return constant(number) if number
end end
@ -62,4 +63,11 @@ class ConditionForm
# if anything else, save it as a constant of string # if anything else, save it as a constant of string
constant(value) constant(value)
end end
def parse_to_number(str)
float = Float(str)
float % 1 == 0 ? float.to_i : float
rescue ArgumentError
nil
end
end end