fix(condition): make condition work with decimal
This commit is contained in:
parent
1b4010205a
commit
22eadafe07
1 changed files with 10 additions and 2 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue