class EacRubyUtils::RecursiveBuilder

Attributes

added[R]
neighbors_block[R]
root[R]
to_check[R]

Public Class Methods

new(root, &neighbors_block) click to toggle source
# File lib/eac_ruby_utils/recursive_builder.rb, line 11
def initialize(root, &neighbors_block)
  @root = root
  @neighbors_block = neighbors_block
end

Private Instance Methods

check_next_item() click to toggle source
# File lib/eac_ruby_utils/recursive_builder.rb, line 38
def check_next_item
  return false unless to_check.any?

  item = to_check.shift
  added << item
  item_neighborhs(item).each { |sub_item| item_try_add_to_check(sub_item) }
  true
end
item_added?(item) click to toggle source
# File lib/eac_ruby_utils/recursive_builder.rb, line 34
def item_added?(item)
  added.include?(item) || to_check.include?(item)
end
item_neighborhs(item) click to toggle source
# File lib/eac_ruby_utils/recursive_builder.rb, line 47
def item_neighborhs(item)
  neighbors_block.call(item)
end
item_try_add_to_check(item) click to toggle source
# File lib/eac_ruby_utils/recursive_builder.rb, line 30
def item_try_add_to_check(item)
  to_check << item unless item_added?(item)
end
result_uncached() click to toggle source
# File lib/eac_ruby_utils/recursive_builder.rb, line 20
def result_uncached
  @added = []
  @to_check = []
  item_try_add_to_check(root)
  while check_next_item
    # Do nothing
  end
  added
end