From 971462dec31382163604899b77320d8126bb91b7 Mon Sep 17 00:00:00 2001 From: Elijah Miller Date: Wed, 19 Mar 2025 20:32:34 -0400 Subject: [PATCH 1/2] Run against latest Ruby 2.6. --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 8bbe6cf..a04abec 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.2 +2.6.10 From bf4b1788ca5fc7a33f7ce4f1ebdfd152b81bb4eb Mon Sep 17 00:00:00 2001 From: Elijah Miller Date: Wed, 19 Mar 2025 20:36:17 -0400 Subject: [PATCH 2/2] Adjust Decimal values to match old BigDecimal behavior from specs. --- lib/frodata/properties/decimal.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/frodata/properties/decimal.rb b/lib/frodata/properties/decimal.rb index bdbc1d9..87d974e 100644 --- a/lib/frodata/properties/decimal.rb +++ b/lib/frodata/properties/decimal.rb @@ -5,7 +5,7 @@ class Decimal < FrOData::Property # Returns the property value, properly typecast # @return [BigDecimal,nil] def value - if (@value.nil? || @value.empty?) && (strict? && allows_nil?) + if (@value.nil? || (@value.respond_to?(:empty?) && @value.empty?)) && (strict? && allows_nil?) nil else BigDecimal(@value) @@ -15,8 +15,9 @@ def value # Sets the property value # @params new_value something BigDecimal() can parse def value=(new_value) - validate(BigDecimal(new_value.to_s)) - @value = new_value.to_s + cleaned_value = clean_value(new_value) + validate(BigDecimal(cleaned_value)) + @value = cleaned_value end # The FrOData type name @@ -32,6 +33,17 @@ def url_value private + # Single pass cleaning a value to make it into a number based on the + # specs in decimal_spec.rb. + def clean_value(value) + BigDecimal(value) # Trigger any underlying exceptions. + value + rescue ArgumentError + clean_value = value.to_s.sub(/[^.[:digit:]].*/, "") + clean_value = "0" if clean_value.bytesize == 0 + clean_value + end + def validate(value) if value > max_value || value < min_value || value.precs.first > 29 validation_error "Value is outside accepted range: #{min_value} to #{max_value}, or has more than 29 significant digits"