Module: REXML::Node
Overview
Represents a node in the tree. Nodes are never encountered except as superclasses of other objects. Nodes have siblings.
Instance Method Summary collapse
-
#each_recursive(&block) ⇒ Object
Visit all subnodes of
selfrecursively. -
#find_first_recursive(&block) ⇒ Object
evaluates to true.
- #indent(to, ind) ⇒ Object
-
#index_in_parent ⇒ Object
Returns the position that
selfholds in its parent’s array, indexed from 1. -
#next_sibling_node ⇒ Object
The next sibling (nil if unset).
- #parent? ⇒ Boolean
-
#previous_sibling_node ⇒ Object
The previous sibling (nil if unset).
- #to_s(indent = -1) ⇒ Object
Instance Method Details
#each_recursive(&block) ⇒ Object
Visit all subnodes of self recursively
42 43 44 45 46 47 |
# File 'lib/rexml/node.rb', line 42 def each_recursive(&block) # :yields: node self.elements.each {|node| block.call(node) node.each_recursive(&block) } end |
#find_first_recursive(&block) ⇒ Object
evaluates to true. Returns nil if none was found.
51 52 53 54 55 56 |
# File 'lib/rexml/node.rb', line 51 def find_first_recursive(&block) # :yields: node each_recursive {|node| return node if block.call(node) } return nil end |
#indent(to, ind) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/rexml/node.rb', line 27 def indent to, ind if @parent and @parent.context and not @parent.context[:indentstyle].nil? then indentstyle = @parent.context[:indentstyle] else indentstyle = ' ' end to << indentstyle*ind unless ind<1 end |
#index_in_parent ⇒ Object
Returns the position that self holds in its parent’s array, indexed from 1.
60 61 62 |
# File 'lib/rexml/node.rb', line 60 def index_in_parent parent.index(self)+1 end |
#next_sibling_node ⇒ Object
Returns the next sibling (nil if unset).
8 9 10 11 |
# File 'lib/rexml/node.rb', line 8 def next_sibling_node return nil if @parent.nil? @parent[ @parent.index(self) + 1 ] end |
#parent? ⇒ Boolean
36 37 38 |
# File 'lib/rexml/node.rb', line 36 def parent? false; end |
#previous_sibling_node ⇒ Object
Returns the previous sibling (nil if unset).
14 15 16 17 18 19 |
# File 'lib/rexml/node.rb', line 14 def previous_sibling_node return nil if @parent.nil? ind = @parent.index(self) return nil if ind == 0 @parent[ ind - 1 ] end |
#to_s(indent = -1) ⇒ Object
21 22 23 24 25 |
# File 'lib/rexml/node.rb', line 21 def to_s indent=-1 rv = "" write rv,indent rv end |