Module: RiCal::PropertyValue::RecurrenceRule::InitializationMethods

Included in:
RiCal::PropertyValue::RecurrenceRule
Defined in:
lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#by_day_scopeObject (readonly)

Returns the value of attribute by_day_scope.



6
7
8
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 6

def by_day_scope
  @by_day_scope
end

Instance Method Details

#add_byrule_strings_to_options_hash(options_hash, key) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 13

def add_byrule_strings_to_options_hash(options_hash, key)
  if (rules = by_list[key])
    if rules.length == 1
      options_hash[key] = rules.first.source
    else
      options_hash[key] = rules.map {|rule| rule.source}
    end
  end
end

#add_to_options_hash(options_hash, key, value) ⇒ Object



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

def add_to_options_hash(options_hash, key, value)
  options_hash[key] = value if value
  options_hash
end

#by_listObject



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

def by_list
  @by_list ||= {}
end

#byday=(val) ⇒ Object



102
103
104
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 102

def byday=(val)
  @by_list_hash[:byday] = val
end

#byhour=(val) ⇒ Object



90
91
92
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 90

def byhour=(val)
  @by_list_hash[:byhour] = val
end

#byminute=(val) ⇒ Object



86
87
88
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 86

def byminute=(val)
  @by_list_hash[:byminute] = val
end

#bymonth=(val) ⇒ Object



94
95
96
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 94

def bymonth=(val)
  @by_list_hash[:bymonth] = val
end

#bymonthday=(val) ⇒ Object



106
107
108
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 106

def bymonthday=(val)
  @by_list_hash[:bymonthday] = val
end

#bysecond=(val) ⇒ Object



82
83
84
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 82

def bysecond=(val)
  @by_list_hash[:bysecond] = val
end

#bysetpos=(val) ⇒ Object



98
99
100
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 98

def bysetpos=(val)
  @by_list_hash[:bysetpos] = val
end

#byweekno=(val) ⇒ Object



114
115
116
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 114

def byweekno=(val)
  @by_list_hash[:byweekno] = val
end

#byyearday=(val) ⇒ Object



110
111
112
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 110

def byyearday=(val)
  @by_list_hash[:byyearday] = val
end

#calc_by_day_scopeObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 66

def calc_by_day_scope
  case freq
  when "YEARLY"
    scope = :yearly
  when "MONTHLY"
    scope = :monthly
  when "WEEKLY"
    scope = :weekly
  else
    scope = :daily
  end
  scope = :monthly if scope != :weekly && @by_list_hash[:bymonth]
  scope = :weekly if scope != :daily && @by_list_hash[:byweekno]
  @by_day_scope = scope
end

#init_by_listsObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 118

def init_by_lists
[:bysecond,
  :byminute,
  :byhour,
  :bymonth,
  :bysetpos
  ].each do |which|
    if val = @by_list_hash[which]
      by_list[which] = [val].flatten.sort
    end
  end
  if val = @by_list_hash[:byday]
    byday_scope =  calc_by_day_scope 
    by_list[:byday] = [val].flatten.map {|day| RecurringDay.new(day, self, byday_scope)}
  end
  if val = @by_list_hash[:bymonthday]
    by_list[:bymonthday] = [val].flatten.map {|md| RecurringMonthDay.new(md)}
  end
  if val = @by_list_hash[:byyearday]
    by_list[:byyearday] = [val].flatten.map {|yd| RecurringYearDay.new(yd)}
  end
  if val = @by_list_hash[:byweekno]
    by_list[:byweekno] = [val].flatten.map {|wkno| RecurringNumberedWeek.new(wkno, self)}
  end
end

#initialize_from_value_part(part, dup_hash) ⇒ Object

:nodoc:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 38

def initialize_from_value_part(part, dup_hash) # :nodoc:
  part_name, value = part.split("=")
  attribute = part_name.downcase
  errors << "Repeated rule part #{attribute} last occurrence was used" if dup_hash[attribute]
  case attribute
  when "freq"
    self.freq = value
  when "wkst"
    self.wkst = value
  when "until"
    @until = PropertyValue.date_or_date_time(self, :value => value)
  when "count"
    @count = value.to_i
  when "interval"
    self.interval = value.to_i
  when "bysecond", "byminute", "byhour", "bymonthday", "byyearday", "byweekno", "bymonth", "bysetpos"
    send("#{attribute}=", value.split(",").map {|int| int.to_i})
  when "byday"
    self.byday = value.split(",")
  else
    errors << "Invalid rule part #{part}"
  end
end

#to_options_hashObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 23

def to_options_hash
  options_hash = {:freq => freq, :interval => interval}
  options_hash[:params] = params unless params.empty?
  add_to_options_hash(options_hash, :count, @count)
  add_to_options_hash(options_hash, :until, @until)
  add_to_options_hash(options_hash, :interval, @interval)
  [:bysecond, :byminute, :byhour, :bymonth, :bysetpos].each do |bypart|
      add_to_options_hash(options_hash, bypart, by_list[bypart])
    end
  [:byday, :bymonthday, :byyearday, :byweekno].each do |bypart|
     add_byrule_strings_to_options_hash(options_hash, bypart)
  end
  options_hash
end