Module: REXML::Node

Included in:
Attribute, Child
Defined in:
lib/rexml/node.rb

Overview

Represents a node in the tree. Nodes are never encountered except as superclasses of other objects. Nodes have siblings.

Instance Method Summary collapse

Instance Method Details

#each_recursive(&block) ⇒ Object

Visit all subnodes of self recursively


53
54
55
56
57
58
# File 'lib/rexml/node.rb', line 53

def each_recursive(&block) # :yields: node
  self.elements.each {|node|
    block.call(node)
    node.each_recursive(&block)
  }
end

#find_first_recursive(&block) ⇒ Object

Find (and return) first subnode (recursively) for which the block evaluates to true. Returns nil if none was found.


62
63
64
65
66
67
# File 'lib/rexml/node.rb', line 62

def find_first_recursive(&block) # :yields: node
  each_recursive {|node|
    return node if block.call(node)
  }
  return nil
end

#indent(to, ind) ⇒ Object


38
39
40
41
42
43
44
45
# File 'lib/rexml/node.rb', line 38

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_parentObject

Returns the position that self holds in its parent's array, indexed from 1.


71
72
73
# File 'lib/rexml/node.rb', line 71

def index_in_parent
  parent.index(self)+1
end

#next_sibling_nodeObject


10
11
12
13
# File 'lib/rexml/node.rb', line 10

def next_sibling_node
  return nil if @parent.nil?
  @parent[ @parent.index(self) + 1 ]
end

#parent?Boolean


47
48
49
# File 'lib/rexml/node.rb', line 47

def parent?
  false;
end

#previous_sibling_nodeObject


16
17
18
19
20
21
# File 'lib/rexml/node.rb', line 16

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 = nil) ⇒ Object

indent

DEPRECATED This parameter is now ignored. See the formatters in the REXML::Formatters package for changing the output style.


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rexml/node.rb', line 26

def to_s indent=nil
  unless indent.nil?
    Kernel.warn( "#{self.class.name}.to_s(indent) parameter is deprecated" )
    f = REXML::Formatters::Pretty.new( indent )
    f.write( self, rv = "" )
  else
    f = REXML::Formatters::Default.new
    f.write( self, rv = "" )
  end
  return rv
end