Class: RiCal::PropertyValue::RecurrenceRule::OccurrenceIncrementer
- Includes:
- TimeManipulation
- Defined in:
- lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/list_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/daily_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/hourly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/weekly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/yearly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_hour_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/monthly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_month_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/minutely_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/secondly_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_minute_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_second_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/frequency_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_yearday_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_monthday_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/null_sub_cycle_incrementer.rb,
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_numbered_day_incrementer.rb
Overview
:nodoc:
Direct Known Subclasses
Defined Under Namespace
Classes: ByDayIncrementer, ByHourIncrementer, ByMinuteIncrementer, ByMonthIncrementer, ByMonthdayIncrementer, ByNumberedDayIncrementer, BySecondIncrementer, ByWeekNoIncrementer, ByYeardayIncrementer, DailyIncrementer, FrequencyIncrementer, HourlyIncrementer, ListIncrementer, MinutelyIncrementer, MonthlyIncrementer, NullSubCycleIncrementer, SecondlyIncrementer, WeeklyIncrementer, YearlyIncrementer
Instance Attribute Summary collapse
-
#contains_daily_incrementer ⇒ Object
Returns the value of attribute contains_daily_incrementer.
-
#contains_weeknum_incrementer ⇒ Object
Returns the value of attribute contains_weeknum_incrementer.
-
#current_occurrence ⇒ Object
Returns the value of attribute current_occurrence.
-
#leaf_iterator ⇒ Object
readonly
Returns the value of attribute leaf_iterator.
-
#outer_incrementers ⇒ Object
Returns the value of attribute outer_incrementers.
-
#outer_range ⇒ Object
Returns the value of attribute outer_range.
-
#sub_cycle_incrementer ⇒ Object
Returns the value of attribute sub_cycle_incrementer.
Class Method Summary collapse
Instance Method Summary collapse
- #add_outer_incrementer(incrementer) ⇒ Object
- #contains_daily_incrementer? ⇒ Boolean
- #contains_weeknum_incrementer? ⇒ Boolean
- #daily_incrementer? ⇒ Boolean
- #first_sub_occurrence(previous_occurrence, outer_cycle_range) ⇒ Object
- #in_outer_cycle?(candidate) ⇒ Boolean
-
#initialize(rrule, sub_cycle_incrementer) ⇒ OccurrenceIncrementer
constructor
A new instance of OccurrenceIncrementer.
-
#next_cycle(previous_occurrence) ⇒ Object
Advance to the next cycle, if the result is within the current cycles of all outer incrementers.
-
#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.
- #outermost? ⇒ Boolean
- #short_name ⇒ Object
- #to_s ⇒ Object
- #update_cycle_range(date_time) ⇒ Object
- #weeknum_incrementer? ⇒ Boolean
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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 34 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_incrementer ⇒ Object
Returns the value of attribute contains_daily_incrementer.
8 9 10 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 8 def contains_daily_incrementer @contains_daily_incrementer end |
#contains_weeknum_incrementer ⇒ Object
Returns the value of attribute contains_weeknum_incrementer.
8 9 10 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 8 def contains_weeknum_incrementer @contains_weeknum_incrementer end |
#current_occurrence ⇒ Object
Returns the value of attribute current_occurrence.
6 7 8 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 6 def current_occurrence @current_occurrence end |
#leaf_iterator ⇒ Object (readonly)
Returns the value of attribute leaf_iterator.
9 10 11 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 9 def leaf_iterator @leaf_iterator end |
#outer_incrementers ⇒ Object
Returns the value of attribute outer_incrementers.
7 8 9 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 7 def outer_incrementers @outer_incrementers end |
#outer_range ⇒ Object
Returns the value of attribute outer_range.
6 7 8 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 6 def outer_range @outer_range end |
#sub_cycle_incrementer ⇒ Object
Returns the value of attribute sub_cycle_incrementer.
6 7 8 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 6 def sub_cycle_incrementer @sub_cycle_incrementer end |
Class Method Details
.from_rrule(recurrence_rule, start_time) ⇒ Object
49 50 51 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 49 def self.from_rrule(recurrence_rule, start_time) YearlyIncrementer.from_rrule(recurrence_rule, start_time) end |
Instance Method Details
#add_outer_incrementer(incrementer) ⇒ Object
53 54 55 56 57 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 53 def add_outer_incrementer(incrementer) @outermost = false self.outer_incrementers << incrementer sub_cycle_incrementer.add_outer_incrementer(incrementer) end |
#contains_daily_incrementer? ⇒ Boolean
115 116 117 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 115 def contains_daily_incrementer? @contains_daily_incrementer end |
#contains_weeknum_incrementer? ⇒ Boolean
123 124 125 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 123 def contains_weeknum_incrementer? @contains_weeknum_incrementer end |
#daily_incrementer? ⇒ Boolean
119 120 121 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 119 def daily_incrementer? false end |
#first_sub_occurrence(previous_occurrence, outer_cycle_range) ⇒ Object
106 107 108 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 106 def first_sub_occurrence(previous_occurrence, outer_cycle_range) first_within_outer_cycle(previous_occurrence, outer_cycle_range) end |
#in_outer_cycle?(candidate) ⇒ Boolean
102 103 104 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 102 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
111 112 113 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 111 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
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 78 def next_time(previous_occurrence) @previous_occurrence = 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
59 60 61 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 59 def outermost? @outermost end |
#short_name ⇒ Object
71 72 73 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 71 def short_name @short_name ||= self.class.name.split("::").last end |
#to_s ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 63 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
97 98 99 100 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 97 def update_cycle_range(date_time) self.current_occurrence = date_time (date_time..end_of_occurrence(date_time)) end |
#weeknum_incrementer? ⇒ Boolean
127 128 129 |
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 127 def weeknum_incrementer? false end |