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.
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
#enumerators ⇒ Object
Returns the value of attribute enumerators.
42 43 44 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 42 def enumerators @enumerators end |
#nexts ⇒ Object
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
64 65 66 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 64 def bounded? @bounded end |
#empty? ⇒ Boolean
51 52 53 |
# File 'lib/ri_cal/occurrence_enumerator.rb', line 51 def empty? @empty end |
#next_occurrence ⇒ Object
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 |