Class: RecurrenceTime

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/recurrence_time.rb

Instance Method Summary collapse

Constructor Details

#initialize(rdata, start_time = JTime.new, strict = true) ⇒ RecurrenceTime

Initializes a RecurrenceTime objects which generates JTime based on recurrence rule

Options

rdata

it can be one of the following:

  1. RRULE, EXRULE, RDATE, and EXDATE lines (RFC 2445 content strings)

  2. RRule or RDateList object

  3. Array of RRule and RDateList objects, which can be a combinations of RRULE and EXRULE

start_time

Optional. Start time of the recurrence time. The default is now

strict

Optional. Any failure to parse should result in a ParseException false causes bad content lines to be logged and ignored. Default is true



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/recurrence_time.rb', line 21

def initialize(rdata, start_time=JTime.new, strict=true)
  rdata = rdata.to_ical if (rdata.kind_of? RRule or
                            rdata.kind_of? RDateList)
  rdata = (rdata.map {|r| r.to_ical}).join("\n") if rdata.kind_of? Array
  # Filter out empty EXDATE because Google Calendar returns empty EXDATE
  rdata.gsub!(/EXDATE.*?:\s*$/, '')
  @iterator = DateTimeIteratorFactory.createDateTimeIterator(rdata, 
              start_time.to_java, 
              start_time.java_zone,
              strict)
  self
end

Instance Method Details

#advance_to(new_start_time) ⇒ Object

Skips all dates in the series before the given date.

Options

new_start_time

JTime which the iterator is advanced to.



44
45
46
47
# File 'lib/recurrence_time.rb', line 44

def advance_to(new_start_time)
  @iterator.advanceTo(new_start_time.to_java)
  self
end

#eachObject



57
58
59
# File 'lib/recurrence_time.rb', line 57

def each
  yield self.next until self.has_next? == false
end

#has_next?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/recurrence_time.rb', line 49

def has_next?
  @iterator.hasNext
end

#nextObject

Returns a JTime for the instance of next recurrence time



35
36
37
# File 'lib/recurrence_time.rb', line 35

def next
  @iterator.hasNext ? JTime.new(@iterator.next) : nil
end

#to_javaObject



53
54
55
# File 'lib/recurrence_time.rb', line 53

def to_java
  @iterator
end