Class: RiCal::PropertyValue::RecurrenceRule::NegativeSetposEnumerator
- Inherits:
-
Enumerator
- Object
- Enumerator
- RiCal::PropertyValue::RecurrenceRule::NegativeSetposEnumerator
- Defined in:
- lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from Enumerator
#base_time, #duration, #next_time, #recurrence_rule, #start_time
Instance Method Summary collapse
- #advance ⇒ Object
- #fill_set ⇒ Object
-
#initialize(recurrence_rule, component, setpos_list) ⇒ NegativeSetposEnumerator
constructor
A new instance of NegativeSetposEnumerator.
- #next_occurrence ⇒ Object
Methods inherited from Enumerator
#bounded?, #empty?, for, #result_occurrence_period, #result_passes_filters?, #result_passes_setpos_filter?
Constructor Details
#initialize(recurrence_rule, component, setpos_list) ⇒ NegativeSetposEnumerator
Returns a new instance of NegativeSetposEnumerator.
6 7 8 9 10 |
# File 'lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb', line 6 def initialize(recurrence_rule, component, setpos_list) super @current_set = [] @valids = [] end |
Instance Method Details
#advance ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb', line 24 def advance if @valids.empty? fill_set @valids = @setpos_list.map {|sp| sp < 0 ? @current_set.length + sp : sp - 1} current_time_index = @current_set.index(@start_time) if current_time_index @valids << current_time_index end @valids = @valids.uniq.sort end @current_set[@valids.shift] end |
#fill_set ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb', line 37 def fill_set @current_set = [next_time] while true self.next_time = @incrementer.next_time(next_time) if recurrence_rule.in_same_set?(@current_set.last, next_time) @current_set << next_time else return end end end |
#next_occurrence ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb', line 12 def next_occurrence while true result = advance if result >= start_time @count += 1 return recurrence_rule.exhausted?(@count, result) ? nil : result_occurrence_period(result) end end end |