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

Inherits:
ListIncrementer show all
Defined in:
lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from ListIncrementer

#cycle_start, #list, #occurrences, #outer_occurrence

Attributes inherited from RiCal::PropertyValue::RecurrenceRule::OccurrenceIncrementer

#contains_daily_incrementer, #contains_weeknum_incrementer, #current_occurrence, #leaf_iterator, #outer_incrementers, #outer_range, #sub_cycle_incrementer

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ListIncrementer

conditional_incrementer, #cycle_adjust, #get_next_occurrences, #next_candidate, #next_cycle, #next_in_list, #occurrences_within

Methods inherited from RiCal::PropertyValue::RecurrenceRule::OccurrenceIncrementer

#add_outer_incrementer, #contains_daily_incrementer?, #contains_weeknum_incrementer?, #daily_incrementer?, #first_sub_occurrence, from_rrule, #in_outer_cycle?, #next_cycle, #next_time, #outermost?, #short_name, #to_s, #update_cycle_range

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, list, sub_cycle_incrementer) ⇒ ByWeekNoIncrementer

include WeeklyBydayMethods



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

def initialize(rrule, list, sub_cycle_incrementer)
  @wkst = rrule.wkst_day
  super(rrule, list, sub_cycle_incrementer)
end

Instance Attribute Details

#wkstObject (readonly)

:nodoc:



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

def wkst
  @wkst
end

Class Method Details

.for_rrule(rrule) ⇒ Object



16
17
18
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb', line 16

def self.for_rrule(rrule)
  conditional_incrementer(rrule, :byweekno, WeeklyIncrementer)
end

Instance Method Details

#advance_cycle(date_time) ⇒ Object



58
59
60
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb', line 58

def advance_cycle(date_time)
  date_time.at_start_of_next_iso_year(wkst)
end

#candidate_acceptable?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb', line 54

def candidate_acceptable?(candidate)
  list.include?(candidate.iso_week_num(wkst))
end

#end_of_occurrence(date_time) ⇒ Object



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

def end_of_occurrence(date_time)
  date_time.end_of_week_with_wkst(wkst)
end

#first_within_outer_cycle(previous_occurrence, outer_range) ⇒ Object



28
29
30
31
32
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb', line 28

def first_within_outer_cycle(previous_occurrence, outer_range)
  new_range_start = outer_range.first
  new_range_end = new_range_start.end_of_iso_year(wkst)
  super(previous_occurrence, outer_range.first..new_range_end)
end

#occurrences_for(date_time) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb', line 39

def occurrences_for(date_time)
  iso_year, year_start = *date_time.iso_year_and_week_one_start(wkst)
  week_one_occurrence = date_time.change(
    :year => year_start.year,
    :month => year_start.month,
    :day => year_start.day
  )
  weeks_in_year_plus_one = week_one_occurrence.iso_weeks_in_year(wkst)
  weeks = list.map {|recurring_weeknum|
    wk_num = recurring_weeknum.ordinal
    (wk_num > 0) ? wk_num : weeks_in_year_plus_one + wk_num
    }.uniq.sort
  weeks.map {|wk_num| week_one_occurrence.advance(:days => (wk_num - 1) * 7)}
end

#start_of_cycle(date_time) ⇒ Object



34
35
36
37
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb', line 34

def start_of_cycle(date_time)
  result = date_time.at_start_of_iso_year(wkst)
  result
end

#unneeded?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb', line 24

def unneeded?(candidate)
  false
end

#weeknum_incrementer?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_weekno_incrementer.rb', line 20

def weeknum_incrementer?
  true
end