Class: RiCal::OccurrenceEnumerator::OccurrenceMerger
- Defined in:
- lib/ri_cal/occurrence_enumerator.rb
Overview
OccurrenceMerger takes multiple recurrence rules and enumerates the combination in sequence.
Instance Attribute Summary collapse
-
#enumerators ⇒ Object
Returns the value of attribute enumerators.
-
#nexts ⇒ Object
Returns the value of attribute nexts.
Class Method Summary collapse
-
.for(component, rules) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #bounded? ⇒ Boolean
-
#initialize(component, rules) ⇒ OccurrenceMerger
constructor
A new instance of OccurrenceMerger.
-
#next_occurrence ⇒ Object
return the earliest of each of the enumerators next occurrences.
Constructor Details
#initialize(component, rules) ⇒ OccurrenceMerger
Returns a new instance of OccurrenceMerger.
39 40 41 42 43 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 39 def initialize(component, rules) self.enumerators = rules.map {|rrule| rrule.enumerator(component)} @bounded = enumerators.all? {|enumerator| enumerator.bounded?} self.nexts = @enumerators.map {|enumerator| enumerator.next_occurrence} end |
Instance Attribute Details
#enumerators ⇒ Object
Returns the value of attribute enumerators.
37 38 39 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 37 def enumerators @enumerators end |
#nexts ⇒ Object
Returns the value of attribute nexts.
37 38 39 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 37 def nexts @nexts end |
Class Method Details
.for(component, rules) ⇒ Object
:nodoc:
27 28 29 30 31 32 33 34 35 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 27 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
54 55 56 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 54 def bounded? @bounded end |
#next_occurrence ⇒ Object
return the earliest of each of the enumerators next occurrences
46 47 48 49 50 51 52 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 46 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 |