Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Fixed RDF::Literal::Double instantiation from "INF"^^xsd:double, "-IN…
Browse files Browse the repository at this point in the history
…F"^^xsd:double, and "NaN"^^xsd:double.

The following all now work as expected:

    RDF::Literal("INF", :datatype => XSD.double).to_f   #=> Infinity
    RDF::Literal("-INF", :datatype => XSD.double).to_f  #=> -Infinity
    RDF::Literal("NaN", :datatype => XSD.double).to_f   #=> NaN
  • Loading branch information
artob authored and mmn80 committed Dec 17, 2010
1 parent cee47fd commit ab730db
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/rdf/model/literal/double.rb
Expand Up @@ -24,10 +24,15 @@ def initialize(value, options = {})
@string = options[:lexical] if options.has_key?(:lexical)
@string = value if !defined?(@string) && value.is_a?(String)
@object = case
when value.is_a?(::String) then Float(value) rescue nil
when value.is_a?(::String) then case value
when 'INF' then 1/0.0
when '-INF' then -1/0.0
when 'NaN' then 0/0.0
else Float(value) rescue nil
end
when value.is_a?(::Float) then value
when value.respond_to?(:to_f) then value.to_f
else Float(value.to_s) rescue nil
else Float(value.to_s) rescue nil # FIXME
end
end

Expand Down

0 comments on commit ab730db

Please sign in to comment.