Method: Jinx::Visitor#initialize

Defined in:
lib/jinx/helpers/visitor.rb

#initialize(opts = nil) {|parent| ... } ⇒ Visitor

Creates a new Visitor which traverses the child objects returned by the navigator block. The navigator block takes a parent node argument and returns an enumerator on the children to visit. The options argument is described in Options.get.

Parameters:

Options Hash (opts):

  • :depth_first (Boolean)

    depth-first traversal

  • :prune_cycle (Boolean)

    flag indicating whether to exclude cycles in a visit

  • :verbose (Boolean)

    print navigation log messages

Yields:

  • (parent)

    returns an enumerator on the children to visit

Yield Parameters:

  • parent

    the current node

Raises:

  • (ArgumentError)


71
72
73
74
75
76
77
78
79
80
81
# File 'lib/jinx/helpers/visitor.rb', line 71

def initialize(opts=nil, &navigator)
  raise ArgumentError.new('Visitor cannot be created without a navigator block') unless block_given?
  @navigator = navigator
  @options = Options.to_hash(opts)
  @depth_first_flag = @options[:depth_first]
  @prune_cycle_flag = @options[:prune_cycle]
  @lineage = []
  @visited = {}
  @verbose = Options.get(:verbose, opts, false)
  @exclude = Set.new
end