Class: TriggerSwitchD::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/trigger_switch_d/action.rb

Overview

Uses the ruby engine to transform code_line into method execute on an instance of Action

Instance Method Summary collapse

Constructor Details

#initialize(code_line, devices, environment = Config.default_environment, date = Date.today) ⇒ Action

Takes a code_line to be scheduled or executed together with the devices, environment and date to validate it.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/trigger_switch_d/action.rb', line 26

def initialize(code_line,devices,environment=Config.default_environment,date=Date.today)
  @name = code_line.strip
  @date = date
  @at_location = environment[:at_location]
  @lookup = environment[:lookup]
  tokens = code_line.scan(/(\w+) (\w+) (\w+) ([\w\d:]+)/u).flatten
  ghost = (class << self;self;end)
  ghost.methodize_device(tokens[1],devices,@lookup)
  @at, executable = __build_executable_at__(tokens)
  ghost.methodize_executable(executable)
end

Instance Method Details

#activate(*args) ⇒ Object

:nodoc:



38
39
40
# File 'lib/trigger_switch_d/action.rb', line 38

def activate(*args) #:nodoc:
  Action.action(:turn_on,*args)
end

#at(*args) ⇒ Object

:nodoc:



46
47
48
49
50
51
52
53
# File 'lib/trigger_switch_d/action.rb', line 46

def at(*args) #:nodoc:
  time = *args
  return @at if time == nil
  if (time =~ /(?:2[0-3]|[01]\d):[0-5]\d/) == 0
    return time
  end
  at_calculated_time(*args)
end

#deactivate(*args) ⇒ Object

:nodoc:



42
43
44
# File 'lib/trigger_switch_d/action.rb', line 42

def deactivate(*args) #:nodoc:
  Action.action(:turn_off,*args)
end

#to_sObject



55
56
57
# File 'lib/trigger_switch_d/action.rb', line 55

def to_s
  @name
end