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
-
#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.
63 64 65 66 67 68 69 70 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 63 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
110 111 112 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 110 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
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 93 def each occurrence = @rrules.next_occurrence yielded = 0 @next_exclusion = @exrules.next_occurrence while (occurrence) if (@cutoff && occurrence[:start] >= @cutoff) || (@count && yielded >= @count) occurrence = nil else unless exclude?(occurrence) yielded += 1 yield @component.recurrence(occurrence) end occurrence = @rrules.next_occurrence end end end |
#exclude?(occurrence) ⇒ Boolean
87 88 89 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 87 def exclude?(occurrence) exclusion_match?(occurrence, exclusion_for(occurrence)) 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
74 75 76 77 78 79 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 74 def exclusion_for(occurrence) while (@next_exclusion && @next_exclusion[:start] < occurrence[:start]) @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
83 84 85 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 83 def exclusion_match?(occurrence, exclusion) exclusion && occurrence[:start] == occurrence[:start] end |
#to_a ⇒ Object Also known as: entries
114 115 116 117 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 114 def to_a raise ArgumentError.new("This component is unbounded, cannot produce an array of occurrences!") unless bounded? super end |