Boolean support for Conversion.to_float
This commit is contained in:
parent
43dab548e9
commit
58aa8f0833
|
@ -63,8 +63,14 @@ module Oga
|
|||
value = value.text
|
||||
end
|
||||
|
||||
if value == true
|
||||
1.0
|
||||
elsif value == false
|
||||
0.0
|
||||
else
|
||||
Float(value) rescue Float::NAN
|
||||
end
|
||||
end
|
||||
|
||||
# @return [TrueClass|FalseClass]
|
||||
def self.to_boolean(value)
|
||||
|
|
|
@ -182,6 +182,18 @@ describe Oga::XPath::Conversion do
|
|||
described_class.to_float(nil).should be_nan
|
||||
end
|
||||
end
|
||||
|
||||
describe 'using a TrueClass' do
|
||||
it 'returns 1.0' do
|
||||
described_class.to_float(true).should == 1.0
|
||||
end
|
||||
end
|
||||
|
||||
describe 'using a FalseClass' do
|
||||
it 'returns 0.0' do
|
||||
described_class.to_float(false).should == 0.0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'to_boolean' do
|
||||
|
|
Loading…
Reference in New Issue