Class: Winever::CronTime
- Inherits:
-
Object
- Object
- Winever::CronTime
- Defined in:
- lib/winever/cron_time.rb
Instance Attribute Summary collapse
-
#day ⇒ Object
Returns the value of attribute day.
-
#dow ⇒ Object
Returns the value of attribute dow.
-
#hour ⇒ Object
Returns the value of attribute hour.
-
#minute ⇒ Object
Returns the value of attribute minute.
-
#month ⇒ Object
Returns the value of attribute month.
-
#parts ⇒ Object
Returns the value of attribute parts.
-
#string ⇒ Object
Returns the value of attribute string.
Instance Method Summary collapse
-
#initialize(cron_time_string) ⇒ CronTime
constructor
A new instance of CronTime.
- #supported? ⇒ Boolean
- #triggers ⇒ Object
- #unsupported_reason ⇒ Object
Constructor Details
#initialize(cron_time_string) ⇒ CronTime
Returns a new instance of CronTime.
5 6 7 8 9 10 11 12 13 |
# File 'lib/winever/cron_time.rb', line 5 def initialize cron_time_string @string = cron_time_string @parts = Array.new(5, '') string_parts = cron_time_string.split(/ +/) @parts[0...string_parts.size] = string_parts @minute, @hour, @day, @month, @dow = @parts end |
Instance Attribute Details
#day ⇒ Object
Returns the value of attribute day.
3 4 5 |
# File 'lib/winever/cron_time.rb', line 3 def day @day end |
#dow ⇒ Object
Returns the value of attribute dow.
3 4 5 |
# File 'lib/winever/cron_time.rb', line 3 def dow @dow end |
#hour ⇒ Object
Returns the value of attribute hour.
3 4 5 |
# File 'lib/winever/cron_time.rb', line 3 def hour @hour end |
#minute ⇒ Object
Returns the value of attribute minute.
3 4 5 |
# File 'lib/winever/cron_time.rb', line 3 def minute @minute end |
#month ⇒ Object
Returns the value of attribute month.
3 4 5 |
# File 'lib/winever/cron_time.rb', line 3 def month @month end |
#parts ⇒ Object
Returns the value of attribute parts.
3 4 5 |
# File 'lib/winever/cron_time.rb', line 3 def parts @parts end |
#string ⇒ Object
Returns the value of attribute string.
3 4 5 |
# File 'lib/winever/cron_time.rb', line 3 def string @string end |
Instance Method Details
#supported? ⇒ Boolean
33 34 35 |
# File 'lib/winever/cron_time.rb', line 33 def supported? unsupported_reason.nil? end |
#triggers ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/winever/cron_time.rb', line 15 def triggers # For now, we don't support anything other than specific time. # But it is possible to handle almost all cron schedule options in the task scheduler of Windows. # It doesn't help that win32-taskscheduler also seems to only support one trigger per task. return [] unless supported? trigger = { :start_year => Date.today.year, :start_month => Date.today.month, :start_day => Date.today.day, :start_hour => hour.to_i, :start_minute => minute.to_i, :trigger_type => Win32::TaskScheduler::TASK_TIME_TRIGGER_DAILY } [trigger] end |
#unsupported_reason ⇒ Object
37 38 39 40 41 42 |
# File 'lib/winever/cron_time.rb', line 37 def unsupported_reason return "Need 5 parts delimited by spaces" if parts.compact.reject(&:empty?).length != 5 return "Only '*' is supported for day, month and day or week parts" if [day, month, dow].detect{|v| v != '*'} return "Only single number is supported for minute and hour parts" if [minute, hour].detect{|v| (v =~ /^\d+$/).nil? } nil end |