Class: Nokogiri::XML::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/eagleclaw/xml.rb

Instance Method Summary collapse

Instance Method Details

#next_until(method = :next_element) {|Nokogiri::XML::Element| ... } ⇒ Object

Keep consuming elements until the block returns ‘true`.

Parameters:

  • method (Symbol) (defaults to: :next_element)

    The method to call on the current element to get the next one. The default is to use ‘:next_element`. Use `:next` to include text elements in the iteration.

Yields:

  • (Nokogiri::XML::Element)

    element The current element. If the block returns ‘true` (or any non-false value) then this is what the method will return.



16
17
18
19
20
21
22
# File 'lib/eagleclaw/xml.rb', line 16

def next_until(method = :next_element)
  current = self
  until yield(current)
    current = current.send(method)
  end
  current
end

#next_while(method = :next_element) ⇒ Object

Keep consuming elements until the block returns ‘false`.

The behaviour of this method is identical to #next_until, only it will keep iterating until the block yields a false value instead of a true one.

See Also:



31
32
33
34
35
36
37
# File 'lib/eagleclaw/xml.rb', line 31

def next_while(method = :next_element)
  current = self
  while yield(current)
    current = current.send(method)
  end
  current
end