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
rubocop:disable Metrics/AbcSize.
-
#current!(&block) ⇒ Object
rubocop:enable Metrics/AbcSize.
- #each(&block) ⇒ Object
-
#initialize ⇒ EventTree
constructor
A new instance of EventTree.
Constructor Details
#initialize ⇒ EventTree
Returns a new instance of EventTree.
9 10 11 |
# File 'lib/rshade/event_tree.rb', line 9 def initialize @current = @head = EventTreeNode.new(nil, 0, nil) end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
7 8 9 |
# File 'lib/rshade/event_tree.rb', line 7 def current @current end |
#head ⇒ Object (readonly)
Returns the value of attribute head.
7 8 9 |
# File 'lib/rshade/event_tree.rb', line 7 def head @head end |
Instance Method Details
#add(value, level) ⇒ Object
rubocop:disable Metrics/AbcSize
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rshade/event_tree.rb', line 14 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 current.children << EventTreeNode.new(nil, current.level + 1, current) unless last @current = current.children.last add(value, level) return end return unless current.level + 1 > level return unless current.parent @current = current.parent add(value, level) end |
#current!(&block) ⇒ Object
rubocop:enable Metrics/AbcSize
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 |