diff --git a/lib/oga/xpath/conversion.rb b/lib/oga/xpath/conversion.rb index fd72f54..ed95f9f 100644 --- a/lib/oga/xpath/conversion.rb +++ b/lib/oga/xpath/conversion.rb @@ -80,6 +80,8 @@ module Oga bool = !value.zero? elsif value.respond_to?(:empty?) bool = !value.empty? + elsif value + bool = true end bool diff --git a/spec/oga/xpath/conversion_spec.rb b/spec/oga/xpath/conversion_spec.rb index f69c260..b7ea936 100644 --- a/spec/oga/xpath/conversion_spec.rb +++ b/spec/oga/xpath/conversion_spec.rb @@ -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