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

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + module RShade class EventTree include Enumerable attr_reader :current, :head @@ -14,25 +16,21 @@ return end if current.level + 1 < level last = current.children.last - unless last - current.children << EventTreeNode.new(nil, current.level + 1 , current) - end + current.children << EventTreeNode.new(nil, current.level + 1, current) unless last @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 + return unless current.level + 1 > level + return unless current.parent + + @current = current.parent + add(value, level) end def current!(&block) block.call(current.children.last) if current.children.last end @@ -45,31 +43,31 @@ class EventTreeNode include Enumerable attr_reader :children, :level, :vlevel, :value attr_accessor :parent - def initialize(value, level, parent=nil) + def initialize(value, level, parent = nil) @children = [] @level = level @parent = parent @value = value @vlevel = set_vlevel(parent) end def each(&block) - block.call(self) if parent != nil || value != nil + block.call(self) if !parent.nil? || !value.nil? children.each { |item| item.each(&block) } end private def set_vlevel(node) - return 0 if node == nil + return 0 if node.nil? - if node.value || node.level == 0 + if node.value || node.level.zero? node.vlevel + 1 else set_vlevel(node.parent) end end end -end \ No newline at end of file +end