Class: IceCube::YearlyRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/ice_cube/rules/yearly_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 whether or not the rule, given a start_date, occurs on a given date. Yearly occurs if we’re in a proper interval and either (1) we’re on a day of the year, or (2) we’re on a month of the year as specified Note: rollover dates don’t work, so you can’t ask for the 400th day of a year and expect to roll into the next year (this might be a possible direction in the future)

Returns:

  • (Boolean)


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

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

#to_icalObject



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

def to_ical 
  'FREQ=YEARLY' << to_ical_base
end

#to_sObject



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

def to_s
  to_s_base 'Yearly', "Every #{@interval} years"
end