Class: IceCube::MonthlyRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/ice_cube/rules/monthly_rule.rb

Instance Attribute Summary

Attributes inherited from Rule

#occurrence_count, #until_date, #validations

Instance Method Summary collapse

Methods inherited from Rule

#count, daily, from_hash, from_yaml, hourly, minutely, monthly, #next_suggestion, secondly, #to_hash, #to_yaml, #until, #validate_single_date, weekly, yearly

Methods included from ValidationTypes

#day, #day_of_month, #day_of_week, #day_of_year, #hour_of_day, #minute_of_hour, #month_of_year, #second_of_minute

Instance Method Details

#in_interval?(date, start_date) ⇒ Boolean

Determine for a given date/start_date if this rule occurs or not. Month rules occur if we’re in a valid interval and either (1) we’re on a valid day of the week (ie: first sunday of the month) or we’re on a valid day of the month (1, 15, -1) Note: Rollover is not implemented, so the 35th day of the month is invalid.

Returns:

  • (Boolean)


10
11
12
13
14
# File 'lib/ice_cube/rules/monthly_rule.rb', line 10

def in_interval?(date, start_date) 
  #make sure we're in the proper interval
  months_to_start_date = (date.month - start_date.month) + (date.year - start_date.year) * 12
  months_to_start_date % @interval == 0
end

#to_icalObject



16
17
18
# File 'lib/ice_cube/rules/monthly_rule.rb', line 16

def to_ical 
  'FREQ=MONTHLY' << to_ical_base
end

#to_sObject



20
21
22
# File 'lib/ice_cube/rules/monthly_rule.rb', line 20

def to_s
  to_s_base 'Monthly', "Every #{@interval} months"
end