Class: RShade::EventTree
- Includes:
- Enumerable
- Defined in:
- lib/rshade/event_tree.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#head ⇒ Object
readonly
Returns the value of attribute head.
Instance Method Summary collapse
- #add(value, level) ⇒ Object
- #current!(&block) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize ⇒ EventTree
constructor
A new instance of EventTree.
Constructor Details
#initialize ⇒ EventTree
Returns a new instance of EventTree.
7 8 9 |
# File 'lib/rshade/event_tree.rb', line 7 def initialize @current = @head = EventTreeNode.new(nil, 0, nil) end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
5 6 7 |
# File 'lib/rshade/event_tree.rb', line 5 def current @current end |
#head ⇒ Object (readonly)
Returns the value of attribute head.
5 6 7 |
# File 'lib/rshade/event_tree.rb', line 5 def head @head end |
Instance Method Details
#add(value, level) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rshade/event_tree.rb', line 11 def add(value, level) if current.level + 1 == level current.children << EventTreeNode.new(value, level, current) return end if current.level + 1 < level last = current.children.last unless last current.children << EventTreeNode.new(nil, current.level + 1 , current) end @current = current.children.last add(value, level) return end if current.level + 1 > level unless current.parent return end @current = current.parent add(value, level) end end |
#current!(&block) ⇒ Object
36 37 38 |
# File 'lib/rshade/event_tree.rb', line 36 def current!(&block) block.call(current.children.last) if current.children.last end |
#each(&block) ⇒ Object
40 41 42 |
# File 'lib/rshade/event_tree.rb', line 40 def each(&block) @head.each(&block) end |