Class: Cadet::Traverser

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/cadet/traverser.rb

Instance Method Summary collapse

Constructor Details

#initialize(nodes, direction, type) ⇒ Traverser

Returns a new instance of Traverser.



5
6
7
8
9
# File 'lib/cadet/traverser.rb', line 5

def initialize(nodes, direction, type)
  @nodes = nodes
  @direction = direction
  @type = type
end

Instance Method Details

#==(other) ⇒ Object



24
25
26
# File 'lib/cadet/traverser.rb', line 24

def ==(other)
  self.to_a == other.to_a
end

#eachObject



11
12
13
14
15
# File 'lib/cadet/traverser.rb', line 11

def each
  @nodes.each do |n|
    n.send(@direction, @type).each { |o| yield o }
  end
end

#incoming(type) ⇒ Object



20
21
22
# File 'lib/cadet/traverser.rb', line 20

def incoming(type)
  Traverser.new to_a, :incoming, type
end

#outgoing(type) ⇒ Object



17
18
19
# File 'lib/cadet/traverser.rb', line 17

def outgoing(type)
  Traverser.new to_a, :outgoing, type
end