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.
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
112 113 114 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 112 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
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 95 def each occurrence = @rrules.next_occurrence yielded = 0 @next_exclusion = @exrules.next_occurrence while (occurrence) if (@cutoff && occurrence[:start].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 |
#exclude?(occurrence) ⇒ Boolean
Also exclude occurrences before the :starting date_time
88 89 90 91 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 88 def exclude?(occurrence) exclusion_match?(occurrence, exclusion_for(occurrence)) || (@start && occurrence[:start].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
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
116 117 118 119 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 116 def to_a raise ArgumentError.new("This component is unbounded, cannot produce an array of occurrences!") unless bounded? super end |