Class: Node

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

Direct Known Subclasses

Body, Contents, Host, Parameter, Request, Result, Section, Text, Version, Xml

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n = nil) ⇒ Node

Returns a new instance of Node.



70
71
72
73
74
# File 'lib/rest.rb', line 70

def initialize n = nil
  @name = n
  @children = Array.new
  @level = 0
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



68
69
70
# File 'lib/rest.rb', line 68

def children
  @children
end

#levelObject

Returns the value of attribute level.



67
68
69
# File 'lib/rest.rb', line 67

def level
  @level
end

#nameObject

Returns the value of attribute name.



67
68
69
# File 'lib/rest.rb', line 67

def name
  @name
end

#parentObject

Returns the value of attribute parent.



67
68
69
# File 'lib/rest.rb', line 67

def parent
  @parent
end

Instance Method Details

#add_child(c) ⇒ Object



76
77
78
79
80
# File 'lib/rest.rb', line 76

def add_child c
  @children.push c
  c.parent = self
  c.level = @level + 1
end

#all_children(type) ⇒ Object



109
110
111
112
113
114
115
116
117
118
# File 'lib/rest.rb', line 109

def all_children type
  @result = Array.new
  @children.each do |child|
    if ( child.class == type )
      @result.push child
    end
    @result.concat( child.all_children( type ) )
  end
  @result
end


82
83
84
# File 'lib/rest.rb', line 82

def print printer
  printer.do_print self
end


86
87
88
89
90
91
92
# File 'lib/rest.rb', line 86

def print_children printer
  if ( @children )
    @children.each do |child|
      child.print printer
    end
  end
end

#rootObject



98
99
100
101
102
103
# File 'lib/rest.rb', line 98

def root
  if parent
    return parent.root
  end
  return self
end

#root?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/rest.rb', line 94

def root?
  return !parent
end

#to_sObject



105
106
107
# File 'lib/rest.rb', line 105

def to_s
  @name
end