Class: Whenever::Output::Cron
- Inherits:
-
Object
- Object
- Whenever::Output::Cron
- Defined in:
- lib/whenever/cron.rb
Constant Summary collapse
- KEYWORDS =
[:reboot, :yearly, :annually, :monthly, :weekly, :daily, :midnight, :hourly]
- REGEX =
/^(@(#{KEYWORDS.join '|'})|.+ .+ .+ .+ .+.?)$/
Instance Attribute Summary collapse
-
#task ⇒ Object
Returns the value of attribute task.
-
#time ⇒ Object
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(time = nil, task = nil, at = nil) ⇒ Cron
constructor
A new instance of Cron.
- #output ⇒ Object
- #time_in_cron_syntax ⇒ Object
Constructor Details
#initialize(time = nil, task = nil, at = nil) ⇒ Cron
Returns a new instance of Cron.
11 12 13 14 15 16 |
# File 'lib/whenever/cron.rb', line 11 def initialize(time = nil, task = nil, at = nil) @at_given = at @time = time @task = task @at = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0) end |
Instance Attribute Details
#task ⇒ Object
Returns the value of attribute task.
9 10 11 |
# File 'lib/whenever/cron.rb', line 9 def task @task end |
#time ⇒ Object
Returns the value of attribute time.
9 10 11 |
# File 'lib/whenever/cron.rb', line 9 def time @time end |
Class Method Details
.enumerate(item, detect_cron = true) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/whenever/cron.rb', line 18 def self.enumerate(item, detect_cron = true) if item and item.is_a?(String) items = if detect_cron && item =~ REGEX [item] else item.split(',') end else items = item items = [items] unless items and items.respond_to?(:each) end items end |
.output(times, job) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/whenever/cron.rb', line 33 def self.output(times, job) enumerate(times).each do |time| enumerate(job.at, false).each do |at| yield new(time, job.output, at).output end end end |
Instance Method Details
#output ⇒ Object
41 42 43 |
# File 'lib/whenever/cron.rb', line 41 def output [time_in_cron_syntax, task].compact.join(' ').strip end |
#time_in_cron_syntax ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/whenever/cron.rb', line 45 def time_in_cron_syntax case @time when REGEX then @time # raw cron sytax given when Symbol then parse_symbol when String then parse_as_string else parse_time end end |