Module: RiCal::OccurrenceEnumerator
- Includes:
- Enumerable
- Defined in:
- lib/ri_cal/occurrence_enumerator.rb
Overview
-
©2009 Rick DeNatale
-
All rights reserved. Refer to the file README.txt for the license
OccurrenceEnumerator provides common methods for CalendarComponents that support recurrence i.e. Event, Journal, Todo, and TimezonePeriod
Defined Under Namespace
Classes: EmptyRulesEnumerator, EnumerationInstance, OccurrenceMerger
Instance Method Summary collapse
-
#bounded? ⇒ Boolean
A predicate which determines whether the component has a bounded set of occurrences.
-
#default_duration ⇒ Object
:nodoc:.
-
#default_start_time ⇒ Object
:nodoc:.
-
#each(&block) ⇒ Object
execute the block for each occurrence.
-
#occurrences(options = {}) ⇒ Object
return an array of occurrences according to the options parameter.
-
#recurrence(occurrence) ⇒ Object
:nodoc:.
-
#set_occurrence_properties!(occurrence) ⇒ Object
:nodoc:.
-
#zulu_occurrence_range ⇒ Object
Return a array whose first element is a UTC DateTime representing the start of the first occurrence, and whose second element is a UTC DateTime representing the end of the last occurrence.
Instance Method Details
#bounded? ⇒ Boolean
A predicate which determines whether the component has a bounded set of occurrences
163 164 165 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 163 def bounded? EnumerationInstance.new(self).bounded? end |
#default_duration ⇒ Object
:nodoc:
11 12 13 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 11 def default_duration # :nodoc: dtend && dtstart.to_ri_cal_date_time_value.duration_until(dtend.to_ri_cal_date_time_value) end |
#default_start_time ⇒ Object
:nodoc:
15 16 17 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 15 def default_start_time # :nodoc: dtstart && dtstart.to_ri_cal_date_time_value end |
#each(&block) ⇒ Object
execute the block for each occurrence
158 159 160 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 158 def each(&block) # :yields: Component EnumerationInstance.new(self).each(&block) end |
#occurrences(options = {}) ⇒ Object
return an array of occurrences according to the options parameter. If a component is not bounded, and the number of occurrences to be returned is not constrained by either the :before, or :count options an ArgumentError will be raised.
The components returned will be the same type as the receiver, but will have any recurrence properties (rrule, rdate, exrule, exdate) removed since they are single occurrences, and will have the recurrence-id property set to the occurrences dtstart value. (see RFC 2445 sec 4.8.4.4 pp 107-109)
parameter options:
- :starting
-
a Date, Time, or DateTime, no occurrences starting before this argument will be returned
- :before
-
a Date, Time, or DateTime, no occurrences starting on or after this argument will be returned.
- :count
-
an integer which limits the number of occurrences returned.
153 154 155 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 153 def occurrences(={}) EnumerationInstance.new(self, ).to_a end |
#recurrence(occurrence) ⇒ Object
:nodoc:
202 203 204 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 202 def recurrence(occurrence) # :nodoc: result = self.dup.set_occurrence_properties!(occurrence) end |
#set_occurrence_properties!(occurrence) ⇒ Object
:nodoc:
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 186 def set_occurrence_properties!(occurrence) # :nodoc: occurrence_end = occurrence.dtend occurrence_start = occurrence.dtstart @rrule_property = nil @exrule_property = nil @rdate_property = nil @exdate_property = nil @recurrence_id_property = occurrence_start if @dtend_property && !occurrence_end occurrence_end = occurrence_start + (@dtend_property - @dtstart_property) end @dtstart_property = dtstart_property.for_occurrence(occurrence_start) @dtend_property = dtend_property.for_occurrence(occurrence_end) if @dtend_property self end |
#zulu_occurrence_range ⇒ Object
Return a array whose first element is a UTC DateTime representing the start of the first occurrence, and whose second element is a UTC DateTime representing the end of the last occurrence. If the receiver is not bounded then the second element will be nil.
The purpose of this method is to provide values which may be used as database attributes so that a query can find all occurence enumerating components which may have occurrences within a range of times.
175 176 177 178 179 180 181 182 183 184 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 175 def zulu_occurrence_range if bounded? all = occurrences first, last = all.first, all.last else first = occurrences(:count => 1).first last = nil end [first.zulu_occurrence_range_start_time, last ? last.zulu_occurrence_range_finish_time : nil] end |