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

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

Overview

:nodoc:

Instance Attribute Summary

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, #first_within_outer_cycle, #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?, #first_sub_occurrence, from_rrule, #in_outer_cycle?, #next_cycle, #next_time, #outermost?, #short_name, #to_s, #update_cycle_range, #weeknum_incrementer?

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, by_monthday_list, by_yearday_list, parent) ⇒ ByDayIncrementer

:nodoc:


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 9

def initialize(rrule, list, by_monthday_list, by_yearday_list, parent)
  super(rrule, list, parent)
  @monthday_filters = by_monthday_list
  @yearday_filters = by_yearday_list
  @by_day_scope = rrule.by_day_scope

  case rrule.by_day_scope
  when :yearly
    @cycle_advance_proc = lambda {|date_time| first_day_of_year(advance_year(date_time))}
    @current_proc = lambda {|date_time| same_year?(current, date_time)}
    @first_day_proc = lambda {|date_time| first_day_of_year(date_time)}
  when :monthly
    @cycle_advance_proc = lambda {|date_time| first_day_of_month(advance_month(date_time))}
    @current_proc = lambda {|date_time| same_month?(current, date_time)}
    @first_day_proc = lambda {|date_time| first_day_of_month(date_time)}
  when :weekly
    @cycle_advance_proc = lambda {|date_time| first_day_of_week(rrule.wkst_day, advance_week(date_time))}
    @current_proc = lambda {|date_time| same_week?(rrule.wkst_day, current, date_time)}
    @first_day_proc = lambda {|date_time| first_day_of_week(rrule.wkst_day, date_time)}
  else
    raise "Invalid recurrence rule, byday needs to be scoped by month, week or year"
  end
end

Class Method Details

.for_rrule(rrule) ⇒ Object


33
34
35
36
37
38
39
40
41
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 33

def self.for_rrule(rrule)
  list = rrule.by_rule_list(:byday)
  if list
    sub_cycle_incrementer = OccurrenceIncrementer::DailyIncrementer.for_rrule(rrule)
    new(rrule, list, rrule.by_rule_list(:bymonthday), rrule.by_rule_list(:byyearday), sub_cycle_incrementer)
  else
    OccurrenceIncrementer::ByYeardayIncrementer.for_rrule(rrule)
  end
end

Instance Method Details

#advance_cycle(date_time) ⇒ Object


75
76
77
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 75

def advance_cycle(date_time)
  @cycle_advance_proc.call(date_time)
end

#candidate_acceptable?(candidate) ⇒ Boolean


67
68
69
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 67

def candidate_acceptable?(candidate)
  list.any? {|recurring_day| recurring_day.include?(candidate)}
end

#daily_incrementer?Boolean


47
48
49
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 47

def daily_incrementer?
  true
end

#end_of_occurrence(date_time) ⇒ Object


79
80
81
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 79

def end_of_occurrence(date_time)
  date_time.end_of_day
end

#occurrences_for(date_time) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 55

def occurrences_for(date_time)
  first_day = start_of_cycle(date_time)
  result = list.map {|recurring_day| recurring_day.matches_for(first_day)}.flatten.uniq.sort
  if @monthday_filters
    result = result.select {|occurrence| @monthday_filters.any? {|recurring_day| recurring_day.include?(occurrence)}}
  end
  if @yearday_filters
    result = result.select {|occurrence| @yearday_filters.any? {|recurring_day| recurring_day.include?(occurrence)}}
  end
  result
end

#start_of_cycle(date_time) ⇒ Object


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

def start_of_cycle(date_time)
  @first_day_proc.call(date_time)
end

#unneeded?(candidate) ⇒ Boolean


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

def unneeded?(candidate)
  false
end

#varying_time_attributeObject


71
72
73
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 71

def varying_time_attribute
  :day
end