Class: Hiccup::Enumerable::ScheduleEnumerator

Inherits:
Object
  • Object
show all
Defined in:
lib/hiccup/enumerable/schedule_enumerator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schedule, date) ⇒ ScheduleEnumerator

Returns a new instance of ScheduleEnumerator.



6
7
8
9
10
11
12
13
# File 'lib/hiccup/enumerable/schedule_enumerator.rb', line 6

def initialize(schedule, date)
  @schedule = schedule
  @date = date
  @date = @date.to_date if @date.respond_to?(:to_date)
  @date = start_date if (@date < start_date)
  @date = end_date if (ends? && @date > end_date)
  @current_date = nil
end

Instance Attribute Details

#scheduleObject (readonly)

Returns the value of attribute schedule.



15
16
17
# File 'lib/hiccup/enumerable/schedule_enumerator.rb', line 15

def schedule
  @schedule
end

Instance Method Details

#first_occurrence_on_or_after(date) ⇒ Object

These two methods DO NOT assume that date is predicted by the given schedule

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/hiccup/enumerable/schedule_enumerator.rb', line 45

def first_occurrence_on_or_after(date)
  raise NotImplementedError
end

#first_occurrence_on_or_before(date) ⇒ Object

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/hiccup/enumerable/schedule_enumerator.rb', line 49

def first_occurrence_on_or_before(date)
  raise NotImplementedError
end

#nextObject



20
21
22
23
24
25
26
27
28
# File 'lib/hiccup/enumerable/schedule_enumerator.rb', line 20

def next
  @current_date = if @current_date
    next_occurrence_after(@current_date)
  else
    first_occurrence_on_or_after(@date)
  end
  @current_date = nil if (ends? && @current_date && @current_date > end_date)
  @current_date
end

#next_occurrence_after(date) ⇒ Object

These two methods DO assume that date is predicted by the given schedule



57
58
59
# File 'lib/hiccup/enumerable/schedule_enumerator.rb', line 57

def next_occurrence_after(date)
  first_occurrence_on_or_after(date + 1)
end

#next_occurrence_before(date) ⇒ Object



61
62
63
# File 'lib/hiccup/enumerable/schedule_enumerator.rb', line 61

def next_occurrence_before(date)
  first_occurrence_on_or_before(date - 1)
end

#prevObject



30
31
32
33
34
35
36
37
38
# File 'lib/hiccup/enumerable/schedule_enumerator.rb', line 30

def prev
  @current_date = if @current_date
    next_occurrence_before(@current_date)
  else
    first_occurrence_on_or_before(@date)
  end
  @current_date = nil if (@current_date && @current_date < start_date)
  @current_date
end