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
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
# File lib/tilia/v_object/recur/r_date_iterator.rb, line 26 def current return nil unless valid @current_date.clone end
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
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
Returns the current item number.
@return [Fixnum]
# File lib/tilia/v_object/recur/r_date_iterator.rb, line 34 def key @counter end
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
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
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
# 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
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