Class: RiCal::OccurrenceEnumerator::EnumerationInstance
- Includes:
- Enumerable
- Defined in:
- lib/ri_cal/occurrence_enumerator.rb
Overview
EnumerationInstance holds the values needed during the enumeration of occurrences for a component.
Instance Method Summary collapse
- #bounded? ⇒ Boolean
-
#each ⇒ Object
yield each occurrence to a block some components may be open-ended, e.g.
-
#exclude?(occurrence) ⇒ Boolean
Also exclude occurrences before the :starting date_time.
-
#exclusion_for(occurrence) ⇒ Object
return the next exclusion which starts at the same time or after the start time of the occurrence return nil if this exhausts the exclusion rules.
-
#exclusion_match?(occurrence, exclusion) ⇒ Boolean
TODO: Need to research this, I beleive that this should also take the end time into account, but I need to research.
-
#initialize(component, options = {}) ⇒ EnumerationInstance
constructor
A new instance of EnumerationInstance.
- #to_a ⇒ Object (also: #entries)
Constructor Details
#initialize(component, options = {}) ⇒ EnumerationInstance
Returns a new instance of EnumerationInstance.
76 77 78 79 80 81 82 83 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 76 def initialize(component, = {}) @component = component @start = [:starting] @cutoff = [:before] @count = [:count] @rrules = OccurrenceMerger.for(@component, [@component.rrule_property, @component.rdate_property].flatten.compact) @exrules = OccurrenceMerger.for(@component, [@component.exrule_property, @component.exdate_property].flatten.compact) end |
Instance Method Details
#bounded? ⇒ Boolean
129 130 131 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 129 def bounded? @rrules.bounded? || @count || @cutoff end |
#each ⇒ Object
yield each occurrence to a block some components may be open-ended, e.g. have no COUNT or DTEND
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 108 def each if @rrules.empty? yield @component else occurrence = @rrules.next_occurrence yielded = 0 @next_exclusion = @exrules.next_occurrence while (occurrence) if (@cutoff && occurrence.dtstart.to_datetime >= @cutoff) || (@count && yielded >= @count) occurrence = nil else unless exclude?(occurrence) yielded += 1 yield @component.recurrence(occurrence) end occurrence = @rrules.next_occurrence end end end end |
#exclude?(occurrence) ⇒ Boolean
Also exclude occurrences before the :starting date_time
101 102 103 104 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 101 def exclude?(occurrence) exclusion_match?(occurrence, exclusion_for(occurrence)) || (@start && occurrence.dtstart.to_datetime < @start) end |
#exclusion_for(occurrence) ⇒ Object
return the next exclusion which starts at the same time or after the start time of the occurrence return nil if this exhausts the exclusion rules
87 88 89 90 91 92 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 87 def exclusion_for(occurrence) while (@next_exclusion && @next_exclusion.dtstart < occurrence.dtstart) @next_exclusion = @exrules.next_occurrence end @next_exclusion end |
#exclusion_match?(occurrence, exclusion) ⇒ Boolean
TODO: Need to research this, I beleive that this should also take the end time into account,
but I need to research
96 97 98 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 96 def exclusion_match?(occurrence, exclusion) exclusion && (occurrence.dtstart == exclusion.dtstart) end |
#to_a ⇒ Object Also known as: entries
133 134 135 136 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 133 def to_a raise ArgumentError.new("This component is unbounded, cannot produce an array of occurrences!") unless bounded? super end |