Class: Nokogiri::XML::Node
- Inherits:
-
Object
- Object
- Nokogiri::XML::Node
- Includes:
- TDiff, TDiff::Unordered
- Defined in:
- lib/nokogiri/diff/xml/node.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#diff(other, options = {}) {|change, node| ... } ⇒ Enumerator
Finds the differences between the node and another node.
-
#tdiff_each_child(node) {|child| ... } ⇒ Object
Enumerates over the children of another XML/HTML node.
-
#tdiff_equal(node) ⇒ Boolean
Compares the XML/HTML node with another.
Instance Method Details
#diff(other, options = {}) {|change, node| ... } ⇒ Enumerator
Finds the differences between the node and another node.
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/nokogiri/diff/xml/node.rb', line 86 def diff(other,={},&block) return enum_for(__method__,other,) unless block if ([:added] || [:removed]) tdiff_unordered(other) do |change,node| if (change == '+' && [:added]) then yield change, node elsif (change == '-' && [:removed]) then yield change, node end end else tdiff(other,&block) end end |
#tdiff_each_child(node) {|child| ... } ⇒ Object
Enumerates over the children of another XML/HTML node.
51 52 53 54 55 56 57 |
# File 'lib/nokogiri/diff/xml/node.rb', line 51 def tdiff_each_child(node,&block) if node.kind_of?(Nokogiri::XML::Element) node.attribute_nodes.sort_by(&:name).each(&block) end node.children.each(&block) end |
#tdiff_equal(node) ⇒ Boolean
Compares the XML/HTML node with another.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nokogiri/diff/xml/node.rb', line 20 def tdiff_equal(node) if (self.class == node.class) case node when Nokogiri::XML::Attr (self.name == node.name && self.value == node.value) when Nokogiri::XML::Element, Nokogiri::XML::DTD self.name == node.name when Nokogiri::XML::Text, Nokogiri::XML::Comment self.text == node.text when Nokogiri::XML::ProcessingInstruction (self.name == node.name && self.content == node.content) else false end else false end end |