Method: Vpim::Rrule#initialize

Defined in:
lib/vpim/rrule.rb

#initialize(dtstart, rrule = nil) ⇒ Rrule

The recurrence rule, rrule, specifies how to generate a set of times from a start time, dtstart (which must the first of the set of recurring times). If rrule is nil, the set contains only dtstart.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/vpim/rrule.rb', line 60

def initialize(dtstart, rrule = nil)
   @dtstart = dtstart.getlocal
   # The getlocal is a hack so that UTC times get converted to local,
   # because yielded times are always local, because we don't support
   # timezones.
   @rrule = rrule

   # Freq is mandatory, but must occur only once.
   @freq = nil

   # Both Until and Count must not occur, neither is OK.
   @until = nil
   @count = nil

   # Interval is optional, but defaults to 1.
   @interval = 1

   # WKST defines what day a week begins on, the default is monday.
   @wkst = 'MO'

   # Recurrence can modified by these.
   @by = {}

   if @rrule
     @rrule.scan(/([^;=]+)=([^;=]+)/) do |key,value|
       key.upcase!
       value.upcase!

       case key
       when 'FREQ'
         @freq = value

       when 'UNTIL'
         if @count
           raise "found UNTIL, but COUNT already specified"
         end
         @until = Rrule.time_from_rfc2425(value)

       when 'COUNT'
         if @until
           raise "found COUNT, but UNTIL already specified"
         end
         @count = value.to_i

       when 'INTERVAL'
         @interval = value.to_i
         if @interval < 1
           raise "interval must be a positive integer"
         end

       when 'WKST'
         # TODO - check value is MO-SU
         @wkst = value

       else
         @by[key] = value
       end
     end

     if !@freq
       # TODO - this shouldn't be an arg error, but a FormatError, its not the
       # caller's fault!
       raise ArgumentError, "recurrence rule lacks a frequency"
     end
   end
end