Module: Hiccup::Enumerable
- Defined in:
- lib/hiccup/enumerable.rb,
lib/hiccup/enumerable/never_enumerator.rb,
lib/hiccup/enumerable/weekly_enumerator.rb,
lib/hiccup/enumerable/monthly_enumerator.rb,
lib/hiccup/enumerable/annually_enumerator.rb,
lib/hiccup/enumerable/schedule_enumerator.rb
Defined Under Namespace
Classes: AnnuallyEnumerator, MonthlyEnumerator, NeverEnumerator, ScheduleEnumerator, WeeklyEnumerator
Instance Method Summary
collapse
Instance Method Details
#enumerator ⇒ Object
13
14
15
|
# File 'lib/hiccup/enumerable.rb', line 13
def enumerator
"Hiccup::Enumerable::#{kind.to_s.classify}Enumerator".constantize
end
|
#first_occurrence_after(date) ⇒ Object
Also known as:
next_occurrence_after
44
45
46
|
# File 'lib/hiccup/enumerable.rb', line 44
def first_occurrence_after(date)
first_occurrence_on_or_after(date.to_date + 1)
end
|
#first_occurrence_before(date) ⇒ Object
56
57
58
|
# File 'lib/hiccup/enumerable.rb', line 56
def first_occurrence_before(date)
first_occurrence_on_or_before(date.to_date - 1)
end
|
#first_occurrence_on_or_after(date) ⇒ Object
39
40
41
42
|
# File 'lib/hiccup/enumerable.rb', line 39
def first_occurrence_on_or_after(date)
return nil if ends? && date > end_date
enumerator.new(self, date).next
end
|
#first_occurrence_on_or_before(date) ⇒ Object
51
52
53
54
|
# File 'lib/hiccup/enumerable.rb', line 51
def first_occurrence_on_or_before(date)
return nil if date < start_date
enumerator.new(self, date).prev
end
|
#n_occurrences_before(limit, date) ⇒ Object
70
71
72
|
# File 'lib/hiccup/enumerable.rb', line 70
def n_occurrences_before(limit, date)
n_occurrences_on_or_before(limit, date.to_date - 1)
end
|
#n_occurrences_on_or_before(limit, date) ⇒ Object
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/hiccup/enumerable.rb', line 74
def n_occurrences_on_or_before(limit, date)
return nil if date < start_date
occurrences = []
enum = enumerator.new(self, date)
while (occurrence = enum.prev) && occurrences.length < limit
occurrences << occurrence
end
occurrences
end
|
#occurrences_between(earlier_date, later_date) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/hiccup/enumerable.rb', line 28
def occurrences_between(earlier_date, later_date)
occurrences = []
enum = enumerator.new(self, earlier_date)
while (occurrence = enum.next) && (occurrence <= later_date)
occurrences << occurrence
end
occurrences
end
|
#occurrences_during_month(year, month) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/hiccup/enumerable.rb', line 19
def occurrences_during_month(year, month)
puts "DEPRECATED: `occurrences_during_month` will be removed in 0.5.0. Use `occurrences_between` instead"
date1 = Date.new(year, month, 1)
date2 = Date.new(year, month, -1)
occurrences_between(date1, date2)
end
|
#occurs_on(date) ⇒ Object
Also known as:
contains?
62
63
64
65
|
# File 'lib/hiccup/enumerable.rb', line 62
def occurs_on(date)
date = date.to_date
date == first_occurrence_on_or_after(date)
end
|