to_boolean support for truthy Ruby values

This commit is contained in:
Yorick Peterse 2015-07-28 19:44:13 +02:00
parent 06ae1503d4
commit 3a18d23792
2 changed files with 8 additions and 0 deletions

View File

@ -80,6 +80,8 @@ module Oga
bool = !value.zero?
elsif value.respond_to?(:empty?)
bool = !value.empty?
elsif value
bool = true
end
bool

View File

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