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 a XML/HTML node.
-
#tdiff_equal(node) ⇒ Boolean
Compares two XML/HTML nodes.
Instance Method Details
#diff(other, options = {}) {|change, node| ... } ⇒ Enumerator
Finds the differences between the node and another node.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/nokogiri/diff/xml/node.rb', line 82 def diff(other,={},&block) return enum_for(:diff,other,) unless block if ([:added] || [:removed]) tdiff_unordered(other) do |change,node| if (change == '+' && [:added]) yield change, node elsif (change == '-' && [:removed]) yield change, node end end else tdiff(other,&block) end end |
#tdiff_each_child(node) {|child| ... } ⇒ Object
Enumerates over the children of a XML/HTML node.
47 48 49 50 51 52 53 |
# File 'lib/nokogiri/diff/xml/node.rb', line 47 def tdiff_each_child(node,&block) if node.kind_of?(Nokogiri::XML::Element) node.attribute_nodes.each(&block) end node.children.each(&block) end |
#tdiff_equal(node) ⇒ Boolean
Compares two XML/HTML nodes.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nokogiri/diff/xml/node.rb', line 19 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 self.text == node.text else false end else false end end |