Class: Hirb::Helpers::Tree::Node
- Inherits:
-
Hash
- Object
- Hash
- Hirb::Helpers::Tree::Node
show all
- Defined in:
- lib/hirb/helpers/tree.rb
Overview
Defined Under Namespace
Classes: MissingLevelError, MissingValueError
Instance Method Summary
collapse
Constructor Details
#initialize(hash) ⇒ Node
Returns a new instance of Node.
142
143
144
145
146
147
|
# File 'lib/hirb/helpers/tree.rb', line 142
def initialize(hash)
super
raise MissingLevelError unless hash.has_key?(:level)
raise MissingValueError unless hash.has_key?(:value)
replace(hash)
end
|
Instance Method Details
#get_parents_character(parent_chars) ⇒ Object
170
171
172
173
174
175
|
# File 'lib/hirb/helpers/tree.rb', line 170
def get_parents_character(parent_chars)
if self.parent
parent_chars << (self.parent[:last_node] ? ' ' : '|') unless self.parent.root?
self.parent.get_parents_character(parent_chars)
end
end
|
#next ⇒ Object
153
154
155
|
# File 'lib/hirb/helpers/tree.rb', line 153
def next
self[:tree].nodes[self[:index] + 1]
end
|
#parent ⇒ Object
149
150
151
|
# File 'lib/hirb/helpers/tree.rb', line 149
def parent
self[:tree].nodes.slice(0 .. self[:index]).reverse.detect {|e| e[:level] < self[:level]}
end
|
#previous ⇒ Object
157
158
159
|
# File 'lib/hirb/helpers/tree.rb', line 157
def previous
self[:tree].nodes[self[:index] - 1]
end
|
#render_parent_characters ⇒ Object
refers to characters which connect parent nodes
164
165
166
167
168
|
# File 'lib/hirb/helpers/tree.rb', line 164
def render_parent_characters
parent_chars = []
get_parents_character(parent_chars)
parent_chars.reverse.map {|level| level + ' ' * 3 }.to_s
end
|
#root? ⇒ Boolean
161
|
# File 'lib/hirb/helpers/tree.rb', line 161
def root?; self[:level] == 0; end
|