to_float support for non String values

This commit is contained in:
Yorick Peterse 2015-08-07 17:08:58 +02:00
parent f3f3c7d31c
commit e3b45fddfc
2 changed files with 7 additions and 5 deletions

View File

@ -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]

View File

@ -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