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

Inherits:
Object
  • Object
show all
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

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

Direct Known Subclasses

FrequencyIncrementer, ListIncrementer

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

Class Method 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.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 36

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.



10
11
12
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 10

def contains_daily_incrementer
  @contains_daily_incrementer
end

#contains_weeknum_incrementerObject

Returns the value of attribute contains_weeknum_incrementer.



10
11
12
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 10

def contains_weeknum_incrementer
  @contains_weeknum_incrementer
end

#current_occurrenceObject

:nodoc:



8
9
10
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 8

def current_occurrence
  @current_occurrence
end

#leaf_iteratorObject (readonly)

Returns the value of attribute leaf_iterator.



11
12
13
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 11

def leaf_iterator
  @leaf_iterator
end

#outer_incrementersObject

Returns the value of attribute outer_incrementers.



9
10
11
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 9

def outer_incrementers
  @outer_incrementers
end

#outer_rangeObject

:nodoc:



8
9
10
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 8

def outer_range
  @outer_range
end

#sub_cycle_incrementerObject

:nodoc:



8
9
10
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 8

def sub_cycle_incrementer
  @sub_cycle_incrementer
end

Class Method Details

.from_rrule(recurrence_rule, start_time) ⇒ Object



51
52
53
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 51

def self.from_rrule(recurrence_rule, start_time)
  YearlyIncrementer.from_rrule(recurrence_rule, start_time)
end

Instance Method Details

#add_outer_incrementer(incrementer) ⇒ Object



55
56
57
58
59
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 55

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)


117
118
119
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 117

def contains_daily_incrementer?
  @contains_daily_incrementer
end

#contains_weeknum_incrementer?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 125

def contains_weeknum_incrementer?
  @contains_weeknum_incrementer
end

#daily_incrementer?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 121

def daily_incrementer?
  false
end

#first_sub_occurrence(previous_occurrence, outer_cycle_range) ⇒ Object



108
109
110
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 108

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)


104
105
106
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 104

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



113
114
115
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 113

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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 80

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

Returns:

  • (Boolean)


61
62
63
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 61

def outermost?
  @outermost
end

#short_nameObject



73
74
75
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 73

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

#to_sObject



65
66
67
68
69
70
71
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 65

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



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

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

#weeknum_incrementer?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer.rb', line 129

def weeknum_incrementer?
  false
end