From 22eadafe07e0f3c089e915de6103d4769584ba8a Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Wed, 8 Nov 2023 12:07:21 +0100 Subject: [PATCH] fix(condition): make condition work with decimal --- app/models/condition_form.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/condition_form.rb b/app/models/condition_form.rb index 1fe815dfe..14e5b4dc9 100644 --- a/app/models/condition_form.rb +++ b/app/models/condition_form.rb @@ -48,9 +48,10 @@ class ConditionForm return empty if value.blank? 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 - number = Integer(value) rescue nil + number = parse_to_number(value) + return constant(number) if number end @@ -62,4 +63,11 @@ class ConditionForm # if anything else, save it as a constant of string constant(value) end + + def parse_to_number(str) + float = Float(str) + float % 1 == 0 ? float.to_i : float + rescue ArgumentError + nil + end end