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.



47
48
49
50
51
52
# File 'lib/ri_cal/occurrence_enumerator.rb', line 47

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.



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

def enumerators
  @enumerators
end

#nextsObject

Returns the value of attribute nexts.



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

def nexts
  @nexts
end

Class Method Details

.for(component, rules) ⇒ Object

:nodoc:



35
36
37
38
39
40
41
42
43
# File 'lib/ri_cal/occurrence_enumerator.rb', line 35

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)


67
68
69
# File 'lib/ri_cal/occurrence_enumerator.rb', line 67

def bounded?
  @bounded
end

#empty?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/ri_cal/occurrence_enumerator.rb', line 54

def empty?
  @empty
end

#next_occurrenceObject

return the earliest of each of the enumerators next occurrences



59
60
61
62
63
64
65
# File 'lib/ri_cal/occurrence_enumerator.rb', line 59

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