Class: ScoutAgent::Order::CheckInOrder

Inherits:
ScoutAgent::Order show all
Defined in:
lib/scout_agent/order/check_in_order.rb

Constant Summary collapse

MATCH_RE =
/\A\s*check[-_]?in(?:\s+(.+?))?\s*\z/

Constants inherited from ScoutAgent::Order

ORDERS_DIR

Instance Attribute Summary

Attributes inherited from ScoutAgent::Order

#match_details, #message

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ScoutAgent::Order

can_handle?, inherited, #initialize, load_all, log, #log, log=, master_agent, match?, #notify_master, subclasses

Constructor Details

This class inherits a constructor from ScoutAgent::Order

Class Method Details

.mission_logObject



9
10
11
12
13
14
15
16
# File 'lib/scout_agent/order/check_in_order.rb', line 9

def self.mission_log
  return @mission_log if defined? @mission_log
  unless db = Database.load(:mission_log, log)
    log.fatal("Could not load mission log database.")
    exit
  end
  @mission_log = db
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/scout_agent/order/check_in_order.rb', line 18

def execute
  if id_str = match_details.captures.first
    ids = id_str.scan(/\d+/).map { |n| n.to_i }
    unless ids.empty?
      s       = ids.size == 1 ? "" : "s"
      ids_str = case ids.size
                when 1 then ids.first.to_s
                when 2 then ids.join(" and ")
                else        ids[0..-2].join(", ") + ", and #{ids.last}"
                end
      log.info("Clearing wait time#{s} for mission#{s} (#{ids_str}).")
      self.class.mission_log.reset_missions(*ids)
    end
  end
  log.info("Requesting an immediate check-in.")
  notify_master
end