Class: GCal4Ruby::Recurrence
- Inherits:
-
Object
- Object
- GCal4Ruby::Recurrence
- Defined in:
- lib/gcal4ruby/recurrence.rb
Overview
The Recurrence class stores information on an Event’s recurrence. The class implements the RFC 2445 iCalendar recurrence description.
Instance Attribute Summary collapse
-
#all_day ⇒ Object
True if the event is all day (i.e. no start/end time).
-
#end ⇒ Object
The event end date/time.
-
#event ⇒ Object
the event reference.
-
#frequency ⇒ Object
The event frequency.
-
#repeat_until ⇒ Object
The date until which the event will be repeated.
-
#start ⇒ Object
The event start date/time.
Instance Method Summary collapse
-
#initialize ⇒ Recurrence
constructor
Returns a new Recurrence object.
-
#to_s ⇒ Object
Returns a string with the correctly formatted ISO 8601 recurrence rule.
Constructor Details
#initialize ⇒ Recurrence
Returns a new Recurrence object
26 27 28 29 30 31 32 33 34 |
# File 'lib/gcal4ruby/recurrence.rb', line 26 def initialize @start = nil @end = nil @event = nil @day_of_week = nil @repeat_until = nil @frequency = nil @all_day = false end |
Instance Attribute Details
#all_day ⇒ Object
True if the event is all day (i.e. no start/end time)
23 24 25 |
# File 'lib/gcal4ruby/recurrence.rb', line 23 def all_day @all_day end |
#end ⇒ Object
The event end date/time
15 16 17 |
# File 'lib/gcal4ruby/recurrence.rb', line 15 def end @end end |
#event ⇒ Object
the event reference
17 18 19 |
# File 'lib/gcal4ruby/recurrence.rb', line 17 def event @event end |
#frequency ⇒ Object
The event frequency
21 22 23 |
# File 'lib/gcal4ruby/recurrence.rb', line 21 def frequency @frequency end |
#repeat_until ⇒ Object
The date until which the event will be repeated
19 20 21 |
# File 'lib/gcal4ruby/recurrence.rb', line 19 def repeat_until @repeat_until end |
#start ⇒ Object
The event start date/time
13 14 15 |
# File 'lib/gcal4ruby/recurrence.rb', line 13 def start @start end |
Instance Method Details
#to_s ⇒ Object
Returns a string with the correctly formatted ISO 8601 recurrence rule
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 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 |
# File 'lib/gcal4ruby/recurrence.rb', line 37 def to_s output = '' if @all_day output += "DTSTART;VALUE=DATE:#{@start.utc.strftime("%Y%m%d")}\n" else output += "DTSTART;VALUE=DATE-TIME:#{@start.complete}\n" end if @all_day output += "DTEND;VALUE=DATE:#{@end.utc.strftime("%Y%m%d")}\n" else output += "DTEND;VALUE=DATE-TIME:#{@end.complete}\n" end output += "RRULE:" if @frequency f = 'FREQ=' i = '' by = '' @frequency.each do |key, v| if v.is_a?(Array) if v.size > 0 value = v.join(",") else value = nil end else value = v end f += "#{key.upcase};" if key != 'interval' case key.downcase when "secondly" by += "BYSECOND=#{value};" when "minutely" by += "BYMINUTE=#{value};" when "hourly" by += "BYHOUR=#{value};" when "weekly" by += "BYDAY=#{value};" if value when "monthly" by += "BYDAY=#{value};" when "yearly" by += "BYYEARDAY=#{value}" when 'interval' i += "INTERVAL=#{value};" end end output += f+i+by end if @repeat_until output += ";UNTIL=#{@repeat_until.strftime("%Y%m%d")}" end output += "\n" end |