Class: AutomationObject::State::AutomaticRouting

Inherits:
Object
  • Object
show all
Defined in:
lib/automation_object/state/helpers/automatic_routing.rb

Constant Summary

MAX_RECURSION_DEPTH =
10

Instance Method Summary collapse

Constructor Details

#initialize(top_state, target) ⇒ AutomaticRouting

Returns a new instance of AutomaticRouting

Parameters:



10
11
12
13
# File 'lib/automation_object/state/helpers/automatic_routing.rb', line 10

def initialize(top_state, target)
  @top = top_state
  @target = target
end

Instance Method Details

#routeBoolean

Returns success or not

Returns:

  • (Boolean)

    success or not



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/automation_object/state/helpers/automatic_routing.rb', line 16

def route
  paths = {}
  @top.active_screens.each do |screen_name, screen|
    paths[screen_name] = recursive_search(screen)
  end

  flattened_paths = flat_hash(paths).keys.sort_by(&:length)
  flattened_paths.each do |flattened_path|
    next unless flattened_path.last == @target
    return follow_route(flattened_path)
  end

  false
end