Class: Nokogiri::XML::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/nokogiri/ext/equality/node.rb,
lib/nokogiri/ext/traverse_text.rb,
lib/nokogiri/ext/traverse_count/node.rb

Direct Known Subclasses

Attr, Document, Element

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Boolean

Determines if the node is similar to another node.

Returns:

  • (Boolean)

    Specifies whether the node is equal, in identity or value, to another node.



18
19
20
21
22
# File 'lib/nokogiri/ext/equality/node.rb', line 18

def ==(other)
  return false unless other

  (self.type == other.type) && (self.name == other.name)
end

#traverse_countInteger

Calculates the sum of all children of the node.

Returns:

  • (Integer)

    The total number of children of the node.



17
18
19
20
21
22
23
# File 'lib/nokogiri/ext/traverse_count/node.rb', line 17

def traverse_count
  count = 0

  traverse { |node| count += 1 }

  return count - 1
end

#traverse_text {|node| ... } ⇒ Enumerator

Traverses all text nodes which are children of the node.

Yields:

  • (node)

    A block will be passed each text node.

Yield Parameters:

Returns:

  • (Enumerator)

    If no block is given, an Enumerator object will be returned.



23
24
25
26
27
28
29
30
31
# File 'lib/nokogiri/ext/traverse_text.rb', line 23

def traverse_text
  return enum_for(:traverse_text) unless block_given?

  yield self if text?

  traverse do |node|
    yield node if node.text?
  end
end