class SayWhen::MonthsCronValue
Constants
- MONTHS
Public Class Methods
new(exp)
click to toggle source
Calls superclass method
SayWhen::CronValue::new
# File lib/say_when/cron_expression.rb, line 369 def initialize(exp) super(:month, 1, 12, exp) end
Public Instance Methods
last(date)
click to toggle source
# File lib/say_when/cron_expression.rb, line 380 def last(date) last_month = values.reverse.detect { |v| v < date.month } result = if last_month.nil? date.change(year: date.year - 1, month: values.last) else date.change(month: last_month) end result.change(day: result.end_of_month, hour: 23, min: 59, sec: 59) end
next(date)
click to toggle source
# File lib/say_when/cron_expression.rb, line 390 def next(date) next_month = values.detect { |v| v > date.month } if next_month.nil? date.change(year: date.year + 1, month: values.first, day: 1, hour: 0) else date.change(month: next_month, day: 1, hour: 0) end end
parse(exp)
click to toggle source
Calls superclass method
SayWhen::CronValue#parse
# File lib/say_when/cron_expression.rb, line 373 def parse(exp) if exp =~ /[A-Z]+/ MONTHS.each_with_index { |mon, index| exp = exp.gsub(mon, (index + 1).to_s) } end super(exp) end