Class: RiCal::PropertyValue::RecurrenceRule::OccurrenceIncrementer

Inherits:
Object
  • Object
show all
Includes:
TimeManipulation
Defined in:
lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb

Overview

  • ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license

Direct Known Subclasses

FrequencyIncrementer, ListIncrementer

Defined Under Namespace

Classes: NullSubCycleIncrementer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TimeManipulation

#advance_day, #advance_month, #advance_week, #advance_year, #first_day_of_month, #first_day_of_week, #first_day_of_year, #first_hour_of_day

Constructor Details

#initialize(rrule, sub_cycle_incrementer) ⇒ OccurrenceIncrementer

Returns a new instance of OccurrenceIncrementer.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 78

def initialize(rrule, sub_cycle_incrementer)
  self.sub_cycle_incrementer = sub_cycle_incrementer
  @outermost = true
  self.outer_incrementers = []
  if sub_cycle_incrementer
    self.contains_daily_incrementer = sub_cycle_incrementer.daily_incrementer? ||
      sub_cycle_incrementer.contains_daily_incrementer?
    self.contains_weeknum_incrementer = sub_cycle_incrementer.weeknum_incrementer?||
      sub_cycle_incrementer.contains_weeknum_incrementer?
    sub_cycle_incrementer.add_outer_incrementer(self)
  else
    self.sub_cycle_incrementer = NullSubCycleIncrementer
  end
end

Instance Attribute Details

#contains_daily_incrementerObject

Returns the value of attribute contains_daily_incrementer.



44
45
46
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 44

def contains_daily_incrementer
  @contains_daily_incrementer
end

#contains_weeknum_incrementerObject

Returns the value of attribute contains_weeknum_incrementer.



44
45
46
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 44

def contains_weeknum_incrementer
  @contains_weeknum_incrementer
end

#current_occurrenceObject

:nodoc:



42
43
44
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 42

def current_occurrence
  @current_occurrence
end

#leaf_iteratorObject (readonly)

Returns the value of attribute leaf_iterator.



45
46
47
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 45

def leaf_iterator
  @leaf_iterator
end

#outer_incrementersObject

Returns the value of attribute outer_incrementers.



43
44
45
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 43

def outer_incrementers
  @outer_incrementers
end

#outer_rangeObject

:nodoc:



42
43
44
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 42

def outer_range
  @outer_range
end

#sub_cycle_incrementerObject

:nodoc:



42
43
44
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 42

def sub_cycle_incrementer
  @sub_cycle_incrementer
end

Instance Method Details

#add_outer_incrementer(incrementer) ⇒ Object



93
94
95
96
97
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 93

def add_outer_incrementer(incrementer)
  @outermost = false
  self.outer_incrementers << incrementer
  sub_cycle_incrementer.add_outer_incrementer(incrementer)
end

#contains_daily_incrementer?Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 154

def contains_daily_incrementer?
  @contains_daily_incrementer
end

#contains_weeknum_incrementer?Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 162

def contains_weeknum_incrementer?
  @contains_weeknum_incrementer
end

#daily_incrementer?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 158

def daily_incrementer?
  false
end

#first_sub_occurrence(previous_occurrence, outer_cycle_range) ⇒ Object



145
146
147
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 145

def first_sub_occurrence(previous_occurrence, outer_cycle_range)
  first_within_outer_cycle(previous_occurrence, outer_cycle_range)
end

#in_outer_cycle?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 141

def in_outer_cycle?(candidate)
  candidate && (outer_range.nil? || (outer_range.first <= candidate && outer_range.last >= candidate))
end

#next_cycle(previous_occurrence) ⇒ Object

Advance to the next cycle, if the result is within the current cycles of all outer incrementers



150
151
152
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 150

def next_cycle(previous_occurrence)
  raise "next_cycle is a subclass responsibility"
end

#next_time(previous_occurrence) ⇒ Object

Return the next time after previous_occurrence generated by this incrementer But the occurrence is outside the current cycle of any outer incrementer(s) return nil which will cause the outer incrementer to step to its next cycle.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 118

def next_time(previous_occurrence)
  if current_occurrence
    sub_occurrence = sub_cycle_incrementer.next_time(previous_occurrence)
  else #first time
    sub_occurrence = sub_cycle_incrementer.first_sub_occurrence(previous_occurrence, update_cycle_range(previous_occurrence))
  end
  if sub_occurrence
    candidate = sub_occurrence
  else
    candidate = next_cycle(previous_occurrence)
  end
  if in_outer_cycle?(candidate)
    candidate
  else
    nil
  end
end

#outermost?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 99

def outermost?
  @outermost
end

#short_nameObject



111
112
113
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 111

def short_name
  @short_name ||= self.class.name.split("::").last
end

#to_sObject



103
104
105
106
107
108
109
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 103

def to_s
  if sub_cycle_incrementer
    "#{self.short_name}->#{sub_cycle_incrementer}"
  else
    self.short_name
  end
end

#update_cycle_range(date_time) ⇒ Object



136
137
138
139
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 136

def update_cycle_range(date_time)
  self.current_occurrence = date_time
  (date_time..end_of_occurrence(date_time))
end

#weeknum_incrementer?Boolean

Returns:

  • (Boolean)


166
167
168
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 166

def weeknum_incrementer?
  false
end