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?
21 22 23 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 21 def errors @errors ||= [] end |
#reset_errors ⇒ Object
:nodoc:
25 26 27 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 25 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
14 15 16 17 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 14 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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 35 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
96 97 98 99 100 101 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 96 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
103 104 105 106 107 108 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 103 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
86 87 88 89 90 91 92 93 94 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 86 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
117 118 119 120 121 122 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 117 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
110 111 112 113 114 115 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 110 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
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 56 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
79 80 81 82 83 84 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 79 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
69 70 71 72 73 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 69 def validate_interval if @interval errors << "interval must be a positive integer" unless @interval > 0 end end |
#validate_termination ⇒ Object
52 53 54 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 52 def validate_termination errors << "COUNT and UNTIL cannot both be specified" if @count && @until end |
#validate_wkst ⇒ Object
75 76 77 |
# File 'lib/ri_cal/property_value/recurrence_rule/validations.rb', line 75 def validate_wkst errors << "#{wkst.inspect} is invalid for wkst" unless %w{MO TU WE TH FR SA SU}.include?(wkst) end |