Module: RiCal::PropertyValue::RecurrenceRule::Validations
- Included in:
- RiCal::PropertyValue::RecurrenceRule
- Defined in:
- lib/ri_cal/property_value/recurrence_rule/validations.rb
Overview
-
©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
Instance Method Summary collapse
-
#errors ⇒ Object
Return any errors found during validation See #valid?.
-
#reset_errors ⇒ Object
:nodoc:.
-
#valid? ⇒ Boolean
Validate that the parameters of the reciever conform to RFC 2445 If errors are found they will be added to the receivers errors.
-
#validate ⇒ Object
Used by #valid? to validate that the parameters of the reciever conform to RFC 2445 If errors are found they will be added to the receivers errors.
- #validate_byday_list ⇒ Object
- #validate_bymonthday_list ⇒ Object
- #validate_bysetpos ⇒ Object
- #validate_byweekno_list ⇒ Object
- #validate_byyearday_list ⇒ Object
- #validate_freq ⇒ Object
- #validate_int_by_list(which, test) ⇒ Object
- #validate_interval ⇒ Object
- #validate_termination ⇒ Object
- #validate_wkst ⇒ Object
Instance Method Details
#errors ⇒ Object
Return any errors found during validation See #valid?
20 21 22 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 20 def errors @errors ||= [] end |
#reset_errors ⇒ Object
:nodoc:
24 25 26 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 24 def reset_errors # :nodoc: @errors = nil end |
#valid? ⇒ Boolean
Validate that the parameters of the reciever conform to RFC 2445 If errors are found they will be added to the receivers errors
Whenever any of the parameters are set, e.g. with:
recurrence_rule.count = 2
the errors will be reset
13 14 15 16 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 13 def valid? validate if @errors.nil? errors.empty? end |
#validate ⇒ Object
Used by #valid? to validate that the parameters of the reciever conform to RFC 2445 If errors are found they will be added to the receivers errors
Whenever any of the parameters are set, e.g. with:
recurrence_rule.count = 2
the errors will be reset
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 34 def validate @errors = [] validate_termination validate_freq validate_interval validate_int_by_list(:bysecond, (0..59)) validate_int_by_list(:byminute, (0..59)) validate_int_by_list(:byhour, (0..23)) validate_int_by_list(:bymonth, (1..12)) validate_bysetpos validate_byday_list validate_bymonthday_list validate_byyearday_list validate_byweekno_list validate_wkst end |
#validate_byday_list ⇒ Object
95 96 97 98 99 100 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 95 def validate_byday_list days = by_list[:byday] || [] days.each do |day| errors << "#{day.source.inspect} is not a valid day" unless day.valid? end end |
#validate_bymonthday_list ⇒ Object
102 103 104 105 106 107 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 102 def validate_bymonthday_list days = by_list[:bymonthday] || [] days.each do |day| errors << "#{day.source.inspect} is not a valid month day" unless day.valid? end end |
#validate_bysetpos ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 85 def validate_bysetpos vals = by_list[:bysetpos] || [] vals.each do |val| errors << "#{val} is invalid for bysetpos" unless (-366..-1) === val || (1..366) === val end unless vals.empty? errors << "bysetpos cannot be used without another by_xxx rule part" unless by_list.length > 1 end end |
#validate_byweekno_list ⇒ Object
116 117 118 119 120 121 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 116 def validate_byweekno_list days = by_list[:byweekno] || [] days.each do |day| errors << "#{day.source.inspect} is not a valid week number" unless day.valid? end end |
#validate_byyearday_list ⇒ Object
109 110 111 112 113 114 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 109 def validate_byyearday_list days = by_list[:byyearday] || [] days.each do |day| errors << "#{day.source.inspect} is not a valid year day" unless day.valid? end end |
#validate_freq ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 55 def validate_freq if @freq unless %w{ SECONDLY MINUTELY HOURLY DAILY WEEKLY MONTHLY YEARLY }.include?(@freq.upcase) errors << "Invalid frequency '#{@freq}'" end else errors << "RecurrenceRule must have a value for FREQ" end end |
#validate_int_by_list(which, test) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 78 def validate_int_by_list(which, test) vals = by_list[which] || [] vals.each do |val| errors << "#{val} is invalid for #{which}" unless test === val end end |
#validate_interval ⇒ Object
68 69 70 71 72 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 68 def validate_interval if @interval errors << "interval must be a positive integer" unless @interval > 0 end end |
#validate_termination ⇒ Object
51 52 53 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 51 def validate_termination errors << "COUNT and UNTIL cannot both be specified" if @count && @until end |
#validate_wkst ⇒ Object
74 75 76 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 74 def validate_wkst errors << "#{wkst.inspect} is invalid for wkst" unless %w{MO TU WE TH FR SA SU}.include?(wkst) end |