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

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

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from ListIncrementer

#cycle_start, #list, #occurrences, #outer_occurrence

Attributes inherited from 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 OccurrenceIncrementer

#add_outer_incrementer, #contains_daily_incrementer?, #contains_weeknum_incrementer?, #daily_incrementer?, #first_sub_occurrence, #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



625
626
627
628
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 625

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

Instance Attribute Details

#wkstObject (readonly)

Returns the value of attribute wkst.



622
623
624
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 622

def wkst
  @wkst
end

Class Method Details

.for_rrule(rrule) ⇒ Object



630
631
632
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 630

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

Instance Method Details

#advance_cycle(date_time) ⇒ Object



668
669
670
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 668

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

#candidate_acceptible?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


664
665
666
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 664

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

#end_of_occurrence(date_time) ⇒ Object



672
673
674
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 672

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

#first_within_outer_cycle(previous_occurrence, outer_range) ⇒ Object



638
639
640
641
642
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 638

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



649
650
651
652
653
654
655
656
657
658
659
660
661
662
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 649

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



644
645
646
647
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 644

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

#weeknum_incrementer?Boolean

Returns:

  • (Boolean)


634
635
636
# File 'lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb', line 634

def weeknum_incrementer?
  true
end