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?
|
||||
elsif value.respond_to?(:empty?)
|
||||
bool = !value.empty?
|
||||
elsif value
|
||||
bool = true
|
||||
end
|
||||
|
||||
bool
|
||||
|
|
|
@ -220,5 +220,11 @@ describe Oga::XPath::Conversion do
|
|||
it 'returns false for an empty NodeSet' do
|
||||
described_class.to_boolean(node_set).should == false
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue