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