class HTML::Node
Public Instance Methods
detach()
click to toggle source
Detach this node from its parent.
# File lib/html/node_ext.rb, line 64 def detach() if @parent @parent.children.delete_if { |child| child.equal?(self) } @parent = nil end self end
each(value = nil) { |self, value| ... }
click to toggle source
Process each node beginning with the current node.
# File lib/html/node_ext.rb, line 74 def each(value = nil, &block) yield self, value if @children @children.each do |child| child.each value, &block end end value end
next_element(name = nil)
click to toggle source
Return the next element after this one. Skips sibling text nodes.
With the name
argument, returns the next element with that
name, skipping other sibling elements.
# File lib/html/node_ext.rb, line 31 def next_element(name = nil) if siblings = parent.children found = false siblings.each do |node| if node.equal?(self) found = true elsif found && node.tag? return node if (name.nil? || node.name == name) end end end nil end
next_sibling()
click to toggle source
Returns the next sibling node.
# File lib/html/node_ext.rb, line 6 def next_sibling() if siblings = parent.children siblings.each_with_index do |node, i| return siblings[i + 1] if node.equal?(self) end end nil end
previous_element(name = nil)
click to toggle source
Return the previous element before this one. Skips sibling text nodes.
Using the name
argument, returns the previous element with
that name, skipping other sibling elements.
# File lib/html/node_ext.rb, line 51 def previous_element(name = nil) if siblings = parent.children found = nil siblings.each do |node| return found if node.equal?(self) found = node if node.tag? && (name.nil? || node.name == name) end end nil end
previous_sibling()
click to toggle source
Returns the previous sibling node.
# File lib/html/node_ext.rb, line 17 def previous_sibling() if siblings = parent.children siblings.each_with_index do |node, i| return siblings[i - 1] if node.equal?(self) end end nil end