Module: Vpim::Icalendar::Property::Recurrence

Included in:
Vevent, Vjournal, Vtodo
Defined in:
lib/vpim/property/recurrence.rb

Overview

Occurrences are calculated from DTSTART and RRULE. If there is no RRULE, the component occurs only once, at the start time.

Limitations:

Only a single RRULE: is currently supported, this is the most common case.

Instance Method Summary collapse

Instance Method Details

#occurrences(dountil = nil, &block) ⇒ Object Also known as: occurences

The times this components occurs. If a block is not provided, returns an enumerator.

Occurrences may be infinite, dountil can be provided to limit the iterations, see Rrule#each.



36
37
38
39
40
41
42
43
# File 'lib/vpim/property/recurrence.rb', line 36

def occurrences(dountil = nil, &block) #:yield: occurrence time
  rr = rrule
  unless block_given?
    return Enumerable::Enumerator.new(self, :occurrences, dountil)
  end

  rr.each(dountil, &block)
end

#occurs_in?(t0, t1) ⇒ Boolean

True if this components occurs in a time period later than t0, but earlier than t1.

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
# File 'lib/vpim/property/recurrence.rb', line 49

def occurs_in?(t0, t1)
  # TODO - deprecate this, its a hack
  occurrences(t1).detect do |tend|
    if respond_to? :duration
      tend += duration || 0
    end
    tend >= t0
  end
end

#rdatesObject

:nodoc:



59
60
61
62
# File 'lib/vpim/property/recurrence.rb', line 59

def rdates #:nodoc:
  # TODO - this is a hack, remove it
  Vpim.decode_date_time_list(propvalue('RDATE'))
end

#rruleObject

:nodoc:



23
24
25
26
27
28
29
# File 'lib/vpim/property/recurrence.rb', line 23

def rrule #:nodoc:
  start = dtstart
  unless start
    raise ArgumentError, "Components without a DTSTART don't have occurrences!"
  end
  Vpim::Rrule.new(start, propvalue('RRULE'))
end