Class: RRule::Context
- Inherits:
-
Object
- Object
- RRule::Context
- Defined in:
- lib/rrule/context.rb
Instance Attribute Summary collapse
-
#day_of_year_mask ⇒ Object
readonly
Returns the value of attribute day_of_year_mask.
-
#dtstart ⇒ Object
readonly
Returns the value of attribute dtstart.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#tz ⇒ Object
readonly
Returns the value of attribute tz.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #elapsed_days_in_year_by_month ⇒ Object
- #first_day_of_year ⇒ Object
- #first_weekday_of_year ⇒ Object
-
#initialize(options, dtstart, tz) ⇒ Context
constructor
A new instance of Context.
- #month_by_day_of_year ⇒ Object
- #month_day_by_day_of_year ⇒ Object
- #negative_month_day_by_day_of_year ⇒ Object
- #negative_week_number_by_day_of_year ⇒ Object
- #next_year_length_in_days ⇒ Object
- #rebuild(year, month) ⇒ Object
- #week_number_by_day_of_year ⇒ Object
- #weekday_by_day_of_year ⇒ Object
- #year_length_in_days ⇒ Object
Constructor Details
#initialize(options, dtstart, tz) ⇒ Context
Returns a new instance of Context.
7 8 9 10 11 |
# File 'lib/rrule/context.rb', line 7 def initialize(, dtstart, tz) @options = @dtstart = dtstart @tz = tz end |
Instance Attribute Details
#day_of_year_mask ⇒ Object (readonly)
Returns the value of attribute day_of_year_mask.
5 6 7 |
# File 'lib/rrule/context.rb', line 5 def day_of_year_mask @day_of_year_mask end |
#dtstart ⇒ Object (readonly)
Returns the value of attribute dtstart.
5 6 7 |
# File 'lib/rrule/context.rb', line 5 def dtstart @dtstart end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/rrule/context.rb', line 5 def @options end |
#tz ⇒ Object (readonly)
Returns the value of attribute tz.
5 6 7 |
# File 'lib/rrule/context.rb', line 5 def tz @tz end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
5 6 7 |
# File 'lib/rrule/context.rb', line 5 def year @year end |
Instance Method Details
#elapsed_days_in_year_by_month ⇒ Object
92 93 94 |
# File 'lib/rrule/context.rb', line 92 def elapsed_days_in_year_by_month @elapsed_days_in_year_by_month ||= [0] + (1..12).map { |month| Date.new(year, month).end_of_month.yday } end |
#first_day_of_year ⇒ Object
60 61 62 |
# File 'lib/rrule/context.rb', line 60 def first_day_of_year @first_day_of_year ||= Date.new(year).beginning_of_year end |
#first_weekday_of_year ⇒ Object
64 65 66 |
# File 'lib/rrule/context.rb', line 64 def first_weekday_of_year @first_weekday_of_year ||= first_day_of_year.wday end |
#month_by_day_of_year ⇒ Object
68 69 70 |
# File 'lib/rrule/context.rb', line 68 def month_by_day_of_year @month_by_day_of_year ||= days_in_year.map(&:month) end |
#month_day_by_day_of_year ⇒ Object
72 73 74 |
# File 'lib/rrule/context.rb', line 72 def month_day_by_day_of_year @month_day_by_day_of_year ||= days_in_year.map(&:day) end |
#negative_month_day_by_day_of_year ⇒ Object
76 77 78 |
# File 'lib/rrule/context.rb', line 76 def negative_month_day_by_day_of_year @negative_month_day_by_day_of_year ||= days_in_year.map { |day| day.day - day.end_of_month.day - 1 } end |
#negative_week_number_by_day_of_year ⇒ Object
88 89 90 |
# File 'lib/rrule/context.rb', line 88 def negative_week_number_by_day_of_year @negative_week_number_by_day_of_year ||= days_in_year.map { |day| day.cweek - Date.new(day.cwyear, 12, 28).cweek - 1 } end |
#next_year_length_in_days ⇒ Object
56 57 58 |
# File 'lib/rrule/context.rb', line 56 def next_year_length_in_days @next_year_length_in_days ||= Date.leap?(year + 1) ? 366 : 365 end |
#rebuild(year, month) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rrule/context.rb', line 13 def rebuild(year, month) @year = year reset_year if year != last_year if [:bynweekday] && ![:bynweekday].empty? && (month != last_month || year != last_year) possible_date_ranges = [] case [:freq] when 'YEARLY' if [:bymonth] [:bymonth].each do |mon| possible_date_ranges.push(elapsed_days_in_year_by_month[(mon - 1)..mon]) end else possible_date_ranges = [[0, year_length_in_days]] end when 'MONTHLY' possible_date_ranges = [elapsed_days_in_year_by_month[(month - 1)..month]] end unless possible_date_ranges.empty? @day_of_year_mask = Array.new(year_length_in_days, false) possible_date_ranges.each do |possible_date_range| year_day_start = possible_date_range[0] year_day_end = possible_date_range[1] - 1 [:bynweekday].each do |weekday| day_of_year = day_of_year_within_range(weekday, year_day_start, year_day_end) day_of_year_mask[day_of_year] = true if day_of_year end end end end @last_year = year @last_month = month end |
#week_number_by_day_of_year ⇒ Object
84 85 86 |
# File 'lib/rrule/context.rb', line 84 def week_number_by_day_of_year @week_number_by_day_of_year ||= days_in_year.map(&:cweek) end |
#weekday_by_day_of_year ⇒ Object
80 81 82 |
# File 'lib/rrule/context.rb', line 80 def weekday_by_day_of_year @weekday_by_day_of_year ||= weekdays_in_year.drop(first_weekday_of_year) end |
#year_length_in_days ⇒ Object
52 53 54 |
# File 'lib/rrule/context.rb', line 52 def year_length_in_days @year_length_in_days ||= leap_year? ? 366 : 365 end |