Class: Hokusai::Automation::DriverCommands::Locate

Inherits:
Base
  • Object
show all
Defined in:
ui/src/hokusai/automation/driver_commands/locate.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#last_parent, #request_id, #state, #status

Instance Method Summary collapse

Methods inherited from Base

#matches_block, #matches_blocks, #mouse_center, #mouse_move

Constructor Details

#initialize(hash) ⇒ Locate

Returns a new instance of Locate.



8
9
10
11
12
13
# File 'ui/src/hokusai/automation/driver_commands/locate.rb', line 8

def initialize(hash)
  @matches = []
  @selectors = nil

  super
end

Instance Attribute Details

#matchesObject (readonly)

Returns the value of attribute matches.



6
7
8
# File 'ui/src/hokusai/automation/driver_commands/locate.rb', line 6

def matches
  @matches
end

Instance Method Details

#execute(blocks, canvas, input) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'ui/src/hokusai/automation/driver_commands/locate.rb', line 29

def execute(blocks, canvas, input)
  if selector = selectors.shift
    if selector.matches(blocks[0])
      Log.debug {"Location match! #{selector}".colorize(:light_magenta)}

      portal = blocks[0].node.portal
      
      Log.debug { "uuid: #{portal.uuid.to_s}".colorize(:light_magenta) }

      matches << portal.uuid.to_s

      selectors.unshift(selector) if selectors.empty?
    else
      selectors.unshift(selector)
    end
  end
end

#on_completeObject



15
16
17
18
19
20
21
22
23
# File 'ui/src/hokusai/automation/driver_commands/locate.rb', line 15

def on_complete
  return if waiting?
  
  done!

  return ::Hokusai::Automation::Error.new("No matches found") if matches.empty?

  matches.last
end

#selectorsObject



25
26
27
# File 'ui/src/hokusai/automation/driver_commands/locate.rb', line 25

def selectors
  @selectors ||= Converters::SelectorConverter.parse_selectors(state[:selector])
end