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
- #empty? ⇒ 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.
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
#enumerators ⇒ Object
Returns the value of attribute enumerators.
45 46 47 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 45 def enumerators @enumerators end |
#nexts ⇒ Object
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
67 68 69 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 67 def bounded? @bounded end |
#empty? ⇒ Boolean
54 55 56 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 54 def empty? @empty end |
#next_occurrence ⇒ Object
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 |