lib/rshade/event_tree.rb in rshade-0.2.0 vs lib/rshade/event_tree.rb in rshade-0.2.1

- old
+ new

@@ -8,10 +8,11 @@ def initialize @current = @head = EventTreeNode.new(nil, 0, nil) end + # rubocop:disable Metrics/AbcSize def add(value, level) if current.level + 1 == level current.children << EventTreeNode.new(value, level, current) return end @@ -28,10 +29,11 @@ return unless current.parent @current = current.parent add(value, level) end + # rubocop:enable Metrics/AbcSize def current!(&block) block.call(current.children.last) if current.children.last end @@ -48,26 +50,26 @@ def initialize(value, level, parent = nil) @children = [] @level = level @parent = parent @value = value - @vlevel = set_vlevel(parent) + @vlevel = vlevel!(parent) end def each(&block) block.call(self) if !parent.nil? || !value.nil? children.each { |item| item.each(&block) } end private - def set_vlevel(node) + def vlevel!(node) return 0 if node.nil? if node.value || node.level.zero? node.vlevel + 1 else - set_vlevel(node.parent) + vlevel!(node.parent) end end end end