diff --git a/lib/oga/xml/node.rb b/lib/oga/xml/node.rb index 817399c..59e8a08 100644 --- a/lib/oga/xml/node.rb +++ b/lib/oga/xml/node.rb @@ -163,6 +163,22 @@ module Oga node_set.insert(index, other) end + + ## + # @return [TrueClass|FalseClass] + # + def html? + root = root_node + + return root.is_a?(Document) && root.html? + end + + ## + # @return [TrueClass|FalseClass] + # + def xml? + return !html? + end end # Element end # XML end # Oga diff --git a/lib/oga/xml/text.rb b/lib/oga/xml/text.rb index 22ac02b..16711b0 100644 --- a/lib/oga/xml/text.rb +++ b/lib/oga/xml/text.rb @@ -48,17 +48,6 @@ module Oga return Entities.encode(super) end - - private - - ## - # @return [TrueClass|FalseClass] - # - def html? - root = root_node - - return root.is_a?(Document) && root.html? - end end # Text end # XML end # Oga diff --git a/spec/oga/xml/node_spec.rb b/spec/oga/xml/node_spec.rb index e35b207..e1c6c86 100644 --- a/spec/oga/xml/node_spec.rb +++ b/spec/oga/xml/node_spec.rb @@ -204,4 +204,36 @@ describe Oga::XML::Node do @container.children[1].should == other end end + + describe '#html?' do + it 'returns true if the node resides within an HTML document' do + node = described_class.new + document = Oga::XML::Document.new(:children => [node], :type => :html) + + node.html?.should == true + end + + it 'returns false if the node resides within an XML document' do + node = described_class.new + document = Oga::XML::Document.new(:children => [node], :type => :xml) + + node.html?.should == false + end + end + + describe '#xml?' do + it 'returns true if the node resides within an XML document' do + node = described_class.new + document = Oga::XML::Document.new(:children => [node], :type => :xml) + + node.xml?.should == true + end + + it 'returns false if the node resides within an HTML document' do + node = described_class.new + document = Oga::XML::Document.new(:children => [node], :type => :html) + + node.xml?.should == false + end + end end