Class: Whenever::Output::Cron

Inherits:
Object
  • Object
show all
Defined in:
lib/outputs/cron.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time = nil, task = nil, at = nil) ⇒ Cron

Returns a new instance of Cron.



8
9
10
11
12
# File 'lib/outputs/cron.rb', line 8

def initialize(time = nil, task = nil, at = nil)
  @time = time
  @task = task
  @at   = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0)
end

Instance Attribute Details

#taskObject

Returns the value of attribute task.



6
7
8
# File 'lib/outputs/cron.rb', line 6

def task
  @task
end

#timeObject

Returns the value of attribute time.



6
7
8
# File 'lib/outputs/cron.rb', line 6

def time
  @time
end

Class Method Details

.output(time, job) ⇒ Object



14
15
16
17
# File 'lib/outputs/cron.rb', line 14

def self.output(time, job)
  out = new(time, job.output, job.at)
  "#{out.time_in_cron_syntax} #{out.task}"
end

Instance Method Details

#time_in_cron_syntaxObject



19
20
21
22
23
24
25
# File 'lib/outputs/cron.rb', line 19

def time_in_cron_syntax
  case @time
    when Symbol then parse_symbol
    when String then parse_as_string
    else parse_time
  end
end