Module: RiCal::PropertyValue::RecurrenceRule::InitializationMethods
- Included in:
- RiCal::PropertyValue::RecurrenceRule
- Defined in:
- lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb
Overview
-
©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
Instance Attribute Summary collapse
-
#by_day_scope ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #add_byrule_strings_to_options_hash(options_hash, key) ⇒ Object
- #add_to_options_hash(options_hash, key, value) ⇒ Object
- #by_list ⇒ Object
- #byday=(val) ⇒ Object
- #byhour=(val) ⇒ Object
- #byminute=(val) ⇒ Object
- #bymonth=(val) ⇒ Object
- #bymonthday=(val) ⇒ Object
- #bysecond=(val) ⇒ Object
- #bysetpos=(val) ⇒ Object
- #byweekno=(val) ⇒ Object
- #byyearday=(val) ⇒ Object
- #calc_by_day_scope ⇒ Object
- #init_by_lists ⇒ Object
-
#initialize_from_value_part(part, dup_hash) ⇒ Object
:nodoc:.
- #to_options_hash ⇒ Object
Instance Attribute Details
#by_day_scope ⇒ Object (readonly)
:nodoc:
8 9 10 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 8 def by_day_scope @by_day_scope end |
Instance Method Details
#add_byrule_strings_to_options_hash(options_hash, key) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 15 def (, key) if (rules = by_list[key]) if rules.length = 1 [key] = rules.first.source else [key] = rules.map {|rule| rule.source} end end end |
#add_to_options_hash(options_hash, key, value) ⇒ Object
10 11 12 13 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 10 def (, key, value) [key] = value if value end |
#by_list ⇒ Object
64 65 66 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 64 def by_list @by_list ||= {} end |
#byday=(val) ⇒ Object
104 105 106 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 104 def byday=(val) @by_list_hash[:byday] = val end |
#byhour=(val) ⇒ Object
92 93 94 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 92 def byhour=(val) @by_list_hash[:byhour] = val end |
#byminute=(val) ⇒ Object
88 89 90 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 88 def byminute=(val) @by_list_hash[:byminute] = val end |
#bymonth=(val) ⇒ Object
96 97 98 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 96 def bymonth=(val) @by_list_hash[:bymonth] = val end |
#bymonthday=(val) ⇒ Object
108 109 110 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 108 def bymonthday=(val) @by_list_hash[:bymonthday] = val end |
#bysecond=(val) ⇒ Object
84 85 86 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 84 def bysecond=(val) @by_list_hash[:bysecond] = val end |
#bysetpos=(val) ⇒ Object
100 101 102 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 100 def bysetpos=(val) @by_list_hash[:bysetpos] = val end |
#byweekno=(val) ⇒ Object
116 117 118 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 116 def byweekno=(val) @by_list_hash[:byweekno] = val end |
#byyearday=(val) ⇒ Object
112 113 114 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 112 def byyearday=(val) @by_list_hash[:byyearday] = val end |
#calc_by_day_scope ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 68 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_lists ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 120 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:
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 40 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_hash ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb', line 25 def = {:freq => freq, :interval => interval} [:params] = params unless params.empty? (, :count, @count) (, :until, @until) (, :interval, @interval) [:bysecond, :byminute, :byhour, :bymonth, :bysetpos].each do |bypart| (, bypart, by_list[bypart]) end [:byday, :bymonthday, :byyearday, :byweekno].each do |bypart| (, bypart) end end |