Class: Tengine::Job::Structure::ElementSelectorNotation::PathFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/tengine/job/structure/element_selector_notation.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, origin, dest) ⇒ PathFinder

Returns a new instance of PathFinder.



142
143
144
145
# File 'lib/tengine/job/structure/element_selector_notation.rb', line 142

def initialize(client, origin, dest)
  @client = client
  @origin, @dest = origin, dest
end

Instance Method Details

#processObject



147
148
149
150
151
152
# File 'lib/tengine/job/structure/element_selector_notation.rb', line 147

def process
  @routes = []
  @current_route = []
  @origin.accept_visitor(self)
  @routes.select{|route| route.last == @dest}
end

#visit(element) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/tengine/job/structure/element_selector_notation.rb', line 154

def visit(element)
  @current_route << element
  if element.is_a?(@client.base_module.const_get(:Edge))
    element.destination.accept_visitor(self)
  else
    @routes << @current_route.dup
    return if element == @dest
    element.next_edges.each do |edge|
      bak = @current_route.dup
      begin
        edge.accept_visitor(self)
      ensure
        @current_route = bak
      end
    end
  end
end