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

.enumerate(item) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/outputs/cron.rb', line 14

def self.enumerate(item)
  if item and item.is_a?(String)
    items = item.split(',')
  else
    items = item
    items = [items] unless items and items.respond_to?(:each)
  end
  items
end

.output(times, job) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/outputs/cron.rb', line 24

def self.output(times, job)
  enumerate(times).each do |time|
    enumerate(job.at).each do |at|
      out = new(time, job.output, at)
      yield "#{out.time_in_cron_syntax} #{out.task}"
    end
  end
end

Instance Method Details

#time_in_cron_syntaxObject



33
34
35
36
37
38
39
# File 'lib/outputs/cron.rb', line 33

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