Module: RiCal::OccurrenceEnumerator

Includes:
Enumerable
Included in:
Component::Event, Component::Journal, Component::Timezone::TimezonePeriod
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

Instance Method Details

#bounded?Boolean

A predicate which determines whether the component has a bounded set of occurrences

Returns:

  • (Boolean)


144
145
146
# File 'lib/ri_cal/occurrence_enumerator.rb', line 144

def bounded?
  EnumerationInstance.new(self).bounded?
end

#default_durationObject

: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)
end

#default_start_timeObject

: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



139
140
141
# File 'lib/ri_cal/occurrence_enumerator.rb', line 139

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.



134
135
136
# File 'lib/ri_cal/occurrence_enumerator.rb', line 134

def occurrences(options={})
  EnumerationInstance.new(self, options).to_a    
end

#recurrence(occurrence) ⇒ Object

:nodoc:



168
169
170
# File 'lib/ri_cal/occurrence_enumerator.rb', line 168

def recurrence(occurrence) # :nodoc:
  result = self.dup.set_occurrence_properties!(occurrence)
end

#set_occurrence_properties!(occurrence) ⇒ Object

:nodoc:



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/ri_cal/occurrence_enumerator.rb', line 148

def set_occurrence_properties!(occurrence) # :nodoc:
  occurrence_end = occurrence[:end]
  occurrence_start = occurrence[:start]
  @rrule_property = nil
  @exrule_property = nil
  @rdate_property = nil
  @exdate_property = nil
  @recurrence_id_property = occurrence_start
  @dtstart_property = occurrence_start
  if occurrence_end
    @dtend_property = occurrence_end
  else
    if dtend
      my_duration = @dtend_property - @dtstart_property
      @dtend_property = occurrence_start + my_duration
    end
  end
  self      
end