Class: Tilia::VObject::Recur::RDateIterator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tilia/v_object/recur/r_date_iterator.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(rrule, start) ⇒ RDateIterator

Creates the Iterator.

Parameters:

  • rrule (String|array)
  • start (Time)


18
19
20
21
22
23
24
# 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

Instance Method Details

#currentObject



26
27
28
29
# 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) ⇒ void

This method returns an undefined value.

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

Parameters:

  • dt (Time)


81
82
83
# 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?Boolean

Returns true if this recurring event never ends.

Returns:

  • (Boolean)


71
72
73
# File 'lib/tilia/v_object/recur/r_date_iterator.rb', line 71

def infinite?
  false
end

#keyFixnum

Returns the current item number.

Returns:

  • (Fixnum)


34
35
36
# File 'lib/tilia/v_object/recur/r_date_iterator.rb', line 34

def key
  @counter
end

#nextvoid

This method returns an undefined value.

Goes on to the next iteration.



57
58
59
60
61
62
63
64
65
66
# 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

#rewindvoid

This method returns an undefined value.

Resets the iterator.



49
50
51
52
# File 'lib/tilia/v_object/recur/r_date_iterator.rb', line 49

def rewind
  @current_date = @start_date.clone
  @counter = 0
end

#validBoolean

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

Returns:

  • (Boolean)


42
43
44
# File 'lib/tilia/v_object/recur/r_date_iterator.rb', line 42

def valid
  @counter <= @dates.size
end