diff --git a/lib/oga/xpath/conversion.rb b/lib/oga/xpath/conversion.rb index ed95f9f..1146427 100644 --- a/lib/oga/xpath/conversion.rb +++ b/lib/oga/xpath/conversion.rb @@ -63,11 +63,7 @@ module Oga value = value.text end - if value.is_a?(String) - value = Float(value) rescue Float::NAN - end - - value + Float(value) rescue Float::NAN end # @return [TrueClass|FalseClass] diff --git a/spec/oga/xpath/conversion_spec.rb b/spec/oga/xpath/conversion_spec.rb index b7ea936..6737b62 100644 --- a/spec/oga/xpath/conversion_spec.rb +++ b/spec/oga/xpath/conversion_spec.rb @@ -176,6 +176,12 @@ describe Oga::XPath::Conversion do described_class.to_float(node).should == 10.5 end end + + describe 'using a NilClass' do + it 'returns Float::NAN' do + described_class.to_float(nil).should be_nan + end + end end describe 'to_boolean' do