Class: Hiccup::Enumerable::WeeklyEnumerator

Inherits:
ScheduleEnumerator show all
Defined in:
lib/hiccup/enumerable/weekly_enumerator.rb

Instance Attribute Summary

Attributes inherited from ScheduleEnumerator

#cursor, #schedule, #seed_date

Instance Method Summary collapse

Methods inherited from ScheduleEnumerator

#ends?, enum_for, #next, #prev, #started?

Constructor Details

#initialize(*args) ⇒ WeeklyEnumerator

Returns a new instance of WeeklyEnumerator.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hiccup/enumerable/weekly_enumerator.rb', line 7

def initialize(*args)
  super
  
  @wday_pattern = weekly_pattern.map do |weekday|
    Date::DAYNAMES.index(weekday)
  end.sort
  
  start_wday = start_date.wday
  if start_wday <= @wday_pattern.first or start_wday > @wday_pattern.last
    @base_date = start_date
  else
    @base_date = start_date - (start_wday - @wday_pattern.first)
  end
  
  @starting_index = wday_pattern.index { |wday| wday >= start_wday } || 0
  @cycle = calculate_cycle(schedule)
end