Skip to content

Commit b3a6504

Browse files
committed
Literal::Decimal must turn Float values into string to avoid Argument error on BigDecimal.
1 parent 146d7fb commit b3a6504

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

lib/rdf/model/literal/decimal.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ def initialize(value, options = {})
2222
@string = options[:lexical] if options.has_key?(:lexical)
2323
@string ||= value if value.is_a?(String)
2424
@object = case
25-
when value.is_a?(BigDecimal) then value
26-
when value.is_a?(Numeric) then BigDecimal(value)
25+
when value.is_a?(::BigDecimal) then value
26+
when value.is_a?(::Float) then BigDecimal(value.to_s)
27+
when value.is_a?(::Numeric) then BigDecimal(value)
2728
else
2829
value = value.to_s
2930
value += "0" if value.end_with?(".") # Normalization required in Ruby 2.4

spec/model_literal_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ def self.literals(*selector)
454454
BigDecimal('1.0') => ["1.0", "1.0"],
455455
BigDecimal('0') => ["0.0", "0.0"],
456456
BigDecimal('10.10') => ["10.1", "10.1"],
457+
1.1 => ["1.1", "1.1"],
457458
}.each do |obj, (str, canon)|
458459
it "to_str #{obj} to #{str.inspect}" do
459460
expect(RDF::Literal::Decimal.new(obj).to_s).to eql str

0 commit comments

Comments
 (0)