class Tilia::VObject::Recur::RDateIterator

RRuleParser.

This class receives an RRULE string, and allows you to iterate to get a list of dates in that recurrence.

For instance, passing: FREQ=DAILY;LIMIT=5 will cause the iterator to contain 5 items, one for each day.

Public Class Methods

new(rrule, start) click to toggle source

Creates the Iterator.

@param [String|array] rrule @param [Time] start

# File lib/tilia/v_object/recur/r_date_iterator.rb, line 18
def initialize(rrule, start)
  @counter = 0
  @dates = []
  @start_date = start
  parse_r_date(rrule)
  @current_date = @start_date.clone
end

Public Instance Methods

current() click to toggle source
# File lib/tilia/v_object/recur/r_date_iterator.rb, line 26
def current
  return nil unless valid
  @current_date.clone
end
fast_forward(dt) click to toggle source

This method allows you to quickly go to the next occurrence after the specified date.

@param [Time] dt

@return [void]

# File lib/tilia/v_object/recur/r_date_iterator.rb, line 81
def fast_forward(dt)
  self.next while valid && @current_date < dt
end
infinite?() click to toggle source

Returns true if this recurring event never ends.

@return [Boolean]

# File lib/tilia/v_object/recur/r_date_iterator.rb, line 71
def infinite?
  false
end
key() click to toggle source

Returns the current item number.

@return [Fixnum]

# File lib/tilia/v_object/recur/r_date_iterator.rb, line 34
def key
  @counter
end
next() click to toggle source

Goes on to the next iteration.

@return [void]

# File lib/tilia/v_object/recur/r_date_iterator.rb, line 57
def next
  @counter += 1

  return nil unless valid

  @current_date = DateTimeParser.parse(
    @dates[@counter - 1],
    @start_date.time_zone
  )
end
rewind() click to toggle source

Resets the iterator.

@return [void]

# File lib/tilia/v_object/recur/r_date_iterator.rb, line 49
def rewind
  @current_date = @start_date.clone
  @counter = 0
end
valid() click to toggle source

Returns whether the current item is a valid item for the recurrence iterator.

@return [Boolean]

# File lib/tilia/v_object/recur/r_date_iterator.rb, line 42
def valid
  @counter <= @dates.size
end

Protected Instance Methods

each() { |d| ... } click to toggle source
# File lib/tilia/v_object/recur/r_date_iterator.rb, line 99
def each
  m = [@start_date.clone]
  n = @dates.map do |d|
    DateTimeParser.parse(d, @start_date.time_zone)
  end
  m.concat n
  m.each do |d|
    yield(d)
  end
end
parse_r_date(rdate) click to toggle source

This method receives a string from an RRULE property, and populates this class with all the values.

@param [String|array] rrule

@return [void]

# File lib/tilia/v_object/recur/r_date_iterator.rb, line 93
def parse_r_date(rdate)
  rdate = rdate.split(',') if rdate.is_a?(String)

  @dates = rdate
end