Added XML::Node#html? and XML::Node#xml?
The former has been moved over from XML::Text, the latter just inverts html?.
This commit is contained in:
parent
4ad502958d
commit
b6fcd326ef
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue