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,
lib/hiccup/enumerable/monthly_date_enumerator.rb

Defined Under Namespace

Classes: AnnuallyEnumerator, MonthlyDateEnumerator, MonthlyEnumerator, NeverEnumerator, ScheduleEnumerator, WeeklyEnumerator

Instance Method Summary collapse

Instance Method Details

#enumeratorObject



13
14
15
# File 'lib/hiccup/enumerable.rb', line 13

def enumerator
  ScheduleEnumerator.enum_for(self)
end

#first_n_occurrences(limit, options = {}) ⇒ Object



78
79
80
# File 'lib/hiccup/enumerable.rb', line 78

def first_n_occurrences(limit, options={})
  n_occurrences_on_or_after(limit, start_date, options)
end

#first_occurrence_after(date) ⇒ Object Also known as: next_occurrence_after



34
35
36
# File 'lib/hiccup/enumerable.rb', line 34

def first_occurrence_after(date)
  first_occurrence_on_or_after(date.to_date + 1)
end

#first_occurrence_before(date) ⇒ Object



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

def first_occurrence_before(date)
  first_occurrence_on_or_before(date.to_date - 1)
end

#first_occurrence_on_or_after(date) ⇒ Object



30
31
32
# File 'lib/hiccup/enumerable.rb', line 30

def first_occurrence_on_or_after(date)
  enumerator.new(self, date).next
end

#first_occurrence_on_or_before(date) ⇒ Object



41
42
43
# File 'lib/hiccup/enumerable.rb', line 41

def first_occurrence_on_or_before(date)
  enumerator.new(self, date).prev
end

#n_occurrences_after(limit, date, options = {}) ⇒ Object



82
83
84
# File 'lib/hiccup/enumerable.rb', line 82

def n_occurrences_after(limit, date, options={})
  n_occurrences_on_or_after(limit, date.to_date + 1, options)
end

#n_occurrences_before(limit, date, options = {}) ⇒ Object



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

def n_occurrences_before(limit, date, options={})
  n_occurrences_on_or_before(limit, date.to_date - 1, options)
end

#n_occurrences_on_or_after(limit, date, options = {}) ⇒ Object



86
87
88
89
90
91
92
93
94
# File 'lib/hiccup/enumerable.rb', line 86

def n_occurrences_on_or_after(limit, date, options={})
  exceptions = options.fetch(:except, [])
  occurrences = []
  enum = enumerator.new(self, date)
  while (occurrence = enum.next) && occurrences.length < limit
    occurrences << occurrence unless exceptions.member?(occurrence)
  end
  occurrences
end

#n_occurrences_on_or_before(limit, date, options = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/hiccup/enumerable.rb', line 66

def n_occurrences_on_or_before(limit, date, options={})
  exceptions = options.fetch(:except, [])
  occurrences = []
  enum = enumerator.new(self, date)
  while (occurrence = enum.prev) && occurrences.length < limit
    occurrences << occurrence unless exceptions.member?(occurrence)
  end
  occurrences
end

#occurrences_between(earlier_date, later_date) ⇒ Object



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

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

#occurs_on(date) ⇒ Object Also known as: contains?, includes?, member?, predicts?



51
52
53
54
# File 'lib/hiccup/enumerable.rb', line 51

def occurs_on(date)
  date = date.to_date
  date == first_occurrence_on_or_after(date)
end