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

Returns a new instance of ByDayIncrementer.



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

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



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

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



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

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

#candidate_acceptable?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 65

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

#daily_incrementer?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 45

def daily_incrementer?
  true
end

#end_of_occurrence(date_time) ⇒ Object



77
78
79
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 77

def end_of_occurrence(date_time)
  date_time.end_of_day
end

#occurrences_for(date_time) ⇒ Object



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

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



49
50
51
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 49

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

#unneeded?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 41

def unneeded?(candidate)
  false
end

#varying_time_attributeObject



69
70
71
# File 'lib/ri_cal/property_value/recurrence_rule/occurrence_incrementer/by_day_incrementer.rb', line 69

def varying_time_attribute
  :day
end