Class: RiCal::PropertyValue::RecurrenceRule::ListIncrementer

Inherits:
OccurrenceIncrementer show all
Defined in:
lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb

Overview

A ListIncrementer represents a byxxx part of a recurrence rule It contains a list of simple values or recurring values It keeps a collection of occurrences within a given range called a cycle When the collection of occurrences is exhausted it is refreshed if there is no outer incrementer, or if a new cycle would start in the current cycle of the outer incrementers.

Instance Attribute Summary collapse

Attributes inherited from OccurrenceIncrementer

#contains_daily_incrementer, #contains_weeknum_incrementer, #current_occurrence, #leaf_iterator, #outer_incrementers, #outer_range, #sub_cycle_incrementer

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OccurrenceIncrementer

#add_outer_incrementer, #contains_daily_incrementer?, #contains_weeknum_incrementer?, #daily_incrementer?, #first_sub_occurrence, #in_outer_cycle?, #next_time, #outermost?, #short_name, #to_s, #update_cycle_range, #weeknum_incrementer?

Methods included from TimeManipulation

#advance_day, #advance_month, #advance_week, #advance_year, #first_day_of_month, #first_day_of_week, #first_day_of_year, #first_hour_of_day

Constructor Details

#initialize(rrule, list, sub_cycle_incrementer) ⇒ ListIncrementer

Returns a new instance of ListIncrementer.



179
180
181
182
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 179

def initialize(rrule, list, sub_cycle_incrementer)
  super(rrule, sub_cycle_incrementer)
  self.list = list
end

Instance Attribute Details

#cycle_startObject

:nodoc:



177
178
179
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 177

def cycle_start
  @cycle_start
end

#listObject

:nodoc:



177
178
179
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 177

def list
  @list
end

#occurrencesObject

:nodoc:



177
178
179
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 177

def occurrences
  @occurrences
end

#outer_occurrenceObject

:nodoc:



177
178
179
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 177

def outer_occurrence
  @outer_occurrence
end

Class Method Details

.conditional_incrementer(rrule, by_part, sub_cycle_class) ⇒ Object



184
185
186
187
188
189
190
191
192
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 184

def self.conditional_incrementer(rrule, by_part, sub_cycle_class)
  sub_cycle_incrementer = sub_cycle_class.for_rrule(rrule)
  list = rrule.by_rule_list(by_part)
  if list
    new(rrule, list, sub_cycle_incrementer)
  else
    sub_cycle_incrementer
  end
end

Instance Method Details

#cycle_adjust(date_time) ⇒ Object



237
238
239
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 237

def cycle_adjust(date_time)
  sub_cycle_incrementer.cycle_adjust(start_of_cycle(date_time))
end

#first_within_outer_cycle(previous_occurrence, outer_range) ⇒ Object



207
208
209
210
211
212
213
214
215
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 207

def first_within_outer_cycle(previous_occurrence, outer_range)
  self.outer_range = outer_range
  self.occurrences = occurrences_within(outer_range)
  occurrences.each { |occurrence|
    sub = sub_cycle_incrementer.first_within_outer_cycle(previous_occurrence, update_cycle_range(occurrence))
    return sub if sub && sub > previous_occurrence
    }
  nil
end

#get_next_occurrencesObject



232
233
234
235
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 232

def get_next_occurrences
  adv_cycle = advance_cycle(start_of_cycle(occurrences.first))
  self.occurrences = occurrences_for(adv_cycle)
end

#next_candidate(date_time) ⇒ Object



217
218
219
220
221
222
223
224
225
226
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 217

def next_candidate(date_time)
  candidate = next_in_list(date_time)
  if outermost?
    while candidate.nil?
      get_next_occurrences
      candidate = next_in_list(date_time)
    end
  end
  candidate
end

#next_cycle(previous_occurrence) ⇒ Object

Advance to the next occurrence, if the result is within the current cycles of all outer incrementers



195
196
197
198
199
200
201
202
203
204
205
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 195

def next_cycle(previous_occurrence)
  unless occurrences
    self.occurrences = occurrences_for(previous_occurrence)
  end
  candidate = next_candidate(previous_occurrence)
  if candidate
    sub_cycle_incrementer.first_within_outer_cycle(previous_occurrence, update_cycle_range(candidate))
  else
    nil
  end
end

#next_in_list(date_time) ⇒ Object



228
229
230
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 228

def next_in_list(date_time)
  occurrences.find {|occurrence| occurrence > date_time}
end

#occurrences_for(date_time) ⇒ Object



241
242
243
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 241

def occurrences_for(date_time)
  list.map {|value| date_time.change(varying_time_attribute => value)}
end

#occurrences_within(date_time_range) ⇒ Object



245
246
247
248
249
250
251
252
253
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 245

def occurrences_within(date_time_range)
  result = []
  date_time = date_time_range.first
  while date_time <= date_time_range.last
     result << occurrences_for(date_time)
     date_time = advance_cycle(date_time)
   end
   result.flatten
end