Class: RiCal::OccurrenceEnumerator::OccurrenceMerger

Inherits:
Object
  • Object
show all
Defined in:
lib/ri_cal/occurrence_enumerator.rb

Overview

OccurrenceMerger takes multiple recurrence rules and enumerates the combination in sequence.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component, rules) ⇒ OccurrenceMerger

Returns a new instance of OccurrenceMerger.



44
45
46
47
48
49
# File 'lib/ri_cal/occurrence_enumerator.rb', line 44

def initialize(component, rules)
  self.enumerators = rules.map {|rrule| rrule.enumerator(component)}
  @bounded = enumerators.all? {|enumerator| enumerator.bounded?}
  @empty = enumerators.all? {|enumerator| enumerator.empty?}
  self.nexts = @enumerators.map {|enumerator| enumerator.next_occurrence}
end

Instance Attribute Details

#enumeratorsObject

Returns the value of attribute enumerators.



42
43
44
# File 'lib/ri_cal/occurrence_enumerator.rb', line 42

def enumerators
  @enumerators
end

#nextsObject

Returns the value of attribute nexts.



42
43
44
# File 'lib/ri_cal/occurrence_enumerator.rb', line 42

def nexts
  @nexts
end

Class Method Details

.for(component, rules) ⇒ Object

:nodoc:



32
33
34
35
36
37
38
39
40
# File 'lib/ri_cal/occurrence_enumerator.rb', line 32

def self.for(component, rules)
  if rules.nil? || rules.empty?
    EmptyRulesEnumerator
  elsif rules.length == 1
    rules.first.enumerator(component)
  else
    new(component, rules)
  end
end

Instance Method Details

#bounded?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/ri_cal/occurrence_enumerator.rb', line 64

def bounded?
  @bounded
end

#empty?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/ri_cal/occurrence_enumerator.rb', line 51

def empty?
  @empty
end

#next_occurrenceObject

return the earliest of each of the enumerators next occurrences



56
57
58
59
60
61
62
# File 'lib/ri_cal/occurrence_enumerator.rb', line 56

def next_occurrence
  result = nexts.compact.sort.first
  if result
    nexts.each_with_index { |datetimevalue, i| @nexts[i] = @enumerators[i].next_occurrence if result == datetimevalue }
  end
  result
end