to_boolean support for truthy Ruby values
This commit is contained in:
parent
06ae1503d4
commit
3a18d23792
|
@ -80,6 +80,8 @@ module Oga
|
||||||
bool = !value.zero?
|
bool = !value.zero?
|
||||||
elsif value.respond_to?(:empty?)
|
elsif value.respond_to?(:empty?)
|
||||||
bool = !value.empty?
|
bool = !value.empty?
|
||||||
|
elsif value
|
||||||
|
bool = true
|
||||||
end
|
end
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -220,5 +220,11 @@ describe Oga::XPath::Conversion do
|
||||||
it 'returns false for an empty NodeSet' do
|
it 'returns false for an empty NodeSet' do
|
||||||
described_class.to_boolean(node_set).should == false
|
described_class.to_boolean(node_set).should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns true for an Element' do
|
||||||
|
element = Oga::XML::Element.new(:name => 'foo')
|
||||||
|
|
||||||
|
described_class.to_boolean(element).should == true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue