Class: Node
- Inherits:
-
Object
show all
- Defined in:
- lib/rest.rb
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
#children ⇒ Object
Returns the value of attribute children.
68
69
70
|
# File 'lib/rest.rb', line 68
def children
@children
end
|
#level ⇒ Object
Returns the value of attribute level.
67
68
69
|
# File 'lib/rest.rb', line 67
def level
@level
end
|
#name ⇒ Object
Returns the value of attribute name.
67
68
69
|
# File 'lib/rest.rb', line 67
def name
@name
end
|
#parent ⇒ Object
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
|
#print(printer) ⇒ Object
82
83
84
|
# File 'lib/rest.rb', line 82
def print printer
printer.do_print self
end
|
#print_children(printer) ⇒ Object
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
|
#root ⇒ Object
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
94
95
96
|
# File 'lib/rest.rb', line 94
def root?
return !parent
end
|
#to_s ⇒ Object
105
106
107
|
# File 'lib/rest.rb', line 105
def to_s
@name
end
|