Module | REXML::Node |
In: |
lib/rexml/node.rb
|
Represents a node in the tree. Nodes are never encountered except as superclasses of other objects. Nodes have siblings.
Visit all subnodes of self recursively
# File lib/rexml/node.rb, line 53 53: def each_recursive(&block) # :yields: node 54: self.elements.each {|node| 55: block.call(node) 56: node.each_recursive(&block) 57: } 58: end
Find (and return) first subnode (recursively) for which the block evaluates to true. Returns nil if none was found.
# File lib/rexml/node.rb, line 62 62: def find_first_recursive(&block) # :yields: node 63: each_recursive {|node| 64: return node if block.call(node) 65: } 66: return nil 67: end
# File lib/rexml/node.rb, line 38 38: def indent to, ind 39: if @parent and @parent.context and not @parent.context[:indentstyle].nil? then 40: indentstyle = @parent.context[:indentstyle] 41: else 42: indentstyle = ' ' 43: end 44: to << indentstyle*ind unless ind<1 45: end
Returns the position that self holds in its parent‘s array, indexed from 1.
# File lib/rexml/node.rb, line 71 71: def index_in_parent 72: parent.index(self)+1 73: end
@return the next sibling (nil if unset)
# File lib/rexml/node.rb, line 10 10: def next_sibling_node 11: return nil if @parent.nil? 12: @parent[ @parent.index(self) + 1 ] 13: end
@return the previous sibling (nil if unset)
# File lib/rexml/node.rb, line 16 16: def previous_sibling_node 17: return nil if @parent.nil? 18: ind = @parent.index(self) 19: return nil if ind == 0 20: @parent[ ind - 1 ] 21: end
indent: | DEPRECATED This parameter is now ignored. See the formatters in the REXML::Formatters package for changing the output style. |
# File lib/rexml/node.rb, line 26 26: def to_s indent=nil 27: unless indent.nil? 28: Kernel.warn( "#{self.class.name}.to_s(indent) parameter is deprecated" ) 29: f = REXML::Formatters::Pretty.new( indent ) 30: f.write( self, rv = "" ) 31: else 32: f = REXML::Formatters::Default.new 33: f.write( self, rv = "" ) 34: end 35: return rv 36: end