Class: Tilia::VObject::Recur::RDateIterator
- Inherits:
-
Object
- Object
- Tilia::VObject::Recur::RDateIterator
- 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
- #current ⇒ Object
-
#fast_forward(dt) ⇒ void
This method allows you to quickly go to the next occurrence after the specified date.
-
#infinite? ⇒ Boolean
Returns true if this recurring event never ends.
-
#initialize(rrule, start) ⇒ RDateIterator
constructor
Creates the Iterator.
-
#key ⇒ Fixnum
Returns the current item number.
-
#next ⇒ void
Goes on to the next iteration.
-
#rewind ⇒ void
Resets the iterator.
-
#valid ⇒ Boolean
Returns whether the current item is a valid item for the recurrence iterator.
Constructor Details
#initialize(rrule, start) ⇒ RDateIterator
Creates the Iterator.
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
#current ⇒ Object
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.
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.
71 72 73 |
# File 'lib/tilia/v_object/recur/r_date_iterator.rb', line 71 def infinite? false end |
#key ⇒ Fixnum
Returns the current item number.
34 35 36 |
# File 'lib/tilia/v_object/recur/r_date_iterator.rb', line 34 def key @counter end |
#next ⇒ void
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 |
#rewind ⇒ void
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 |
#valid ⇒ Boolean
Returns whether the current item is a valid item for the recurrence iterator.
42 43 44 |
# File 'lib/tilia/v_object/recur/r_date_iterator.rb', line 42 def valid @counter <= @dates.size end |