Class: Icalendar::Rrule::Occurrence
- Inherits:
-
Object
- Object
- Icalendar::Rrule::Occurrence
- Includes:
- Comparable
- Defined in:
- lib/icalendar/rrule/occurrence.rb
Overview
An Occurrence represents the point of time where an event or any other component of an iCalendar happens.
A component with a repeat rule happens several times. Such a component is represented by a set of many Occurrence instances. All these occurrence instances refer to the same component called herein the base_component.
The base_component can be one of the following:
- Icalendar::Event
- Icalendar::Todo
furthermore it can also be one of the following:
- Icalendar::Freebusy
- Icalendar::Journal
but these are not tested in the current version of this GEM.
The Occurrence delegates reading of attributes to its underlying base_component.
Instance Attribute Summary collapse
-
#base_calendar ⇒ Icalendar::Calendar
readonly
The calendar this occurrence is taken from.
-
#base_component ⇒ Icalendar::Component
readonly
The calendar-component (an event or a task) this occurrence refers to.
-
#end_time ⇒ ActiveSupport::TimeWithZone
readonly
The end of this occurrence.
-
#start_time ⇒ ActiveSupport::TimeWithZone
readonly
The start of this occurrence.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compares this occurrence to the other.
-
#initialize(base_calendar, base_component, start_time, end_time) ⇒ Occurrence
constructor
Create a new Occurrence instance.
-
#method_missing(method_name, *arguments, &block) ⇒ Object
Invoked by Ruby when the Occurrence-object is sent a message it cannot handle.
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Returns true if the Occurrence can respond to the given method, that is, the base component responds to the given method.
-
#time_zone ⇒ ActiveSupport::TimeZone
The timezone used in this component.
Constructor Details
#initialize(base_calendar, base_component, start_time, end_time) ⇒ Occurrence
Create a new Occurrence instance.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/icalendar/rrule/occurrence.rb', line 61 def initialize(base_calendar, base_component, start_time, end_time) raise ArgumentError, "'base_calendar' not of class 'Icalendar::Calendar'" unless base_calendar.nil? || base_calendar.is_a?(Icalendar::Calendar) raise ArgumentError, "'base_component' not of class 'Icalendar::Component'" unless base_component.is_a?(Icalendar::Component) raise ArgumentError, "'start_time' not of class 'ActiveSupport::TimeWithZone'" unless start_time.is_a?(ActiveSupport::TimeWithZone) raise ArgumentError, "'end_time' not of class 'ActiveSupport::TimeWithZone'" unless end_time.is_a?(ActiveSupport::TimeWithZone) @base_calendar = base_calendar @base_component = base_component @start_time = start_time @end_time = end_time super() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
Invoked by Ruby when the Occurrence-object is sent a message it cannot handle.
Reading of attributes will be delegated all to the base component.
An attempt to set an attribute will result in an error.
89 90 91 92 93 94 95 96 97 |
# File 'lib/icalendar/rrule/occurrence.rb', line 89 def method_missing(method_name, *arguments, &block) if method_name.to_s[-1, 1] == '=' # do not allow for setter methods super else # delegate all other requests to the base component base_component.send(method_name, *arguments, &block) end end |
Instance Attribute Details
#base_calendar ⇒ Icalendar::Calendar (readonly)
Returns the calendar this occurrence is taken from.
39 40 41 |
# File 'lib/icalendar/rrule/occurrence.rb', line 39 def base_calendar @base_calendar end |
#base_component ⇒ Icalendar::Component (readonly)
Returns the calendar-component (an event or a task) this occurrence refers to.
42 43 44 |
# File 'lib/icalendar/rrule/occurrence.rb', line 42 def base_component @base_component end |
#end_time ⇒ ActiveSupport::TimeWithZone (readonly)
Returns the end of this occurrence.
48 49 50 |
# File 'lib/icalendar/rrule/occurrence.rb', line 48 def end_time @end_time end |
#start_time ⇒ ActiveSupport::TimeWithZone (readonly)
Returns the start of this occurrence.
45 46 47 |
# File 'lib/icalendar/rrule/occurrence.rb', line 45 def start_time @start_time end |
Instance Method Details
#<=>(other) ⇒ Object
Compares this occurrence to the other. Comparison is on:
- @start_time
- @end_time
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/icalendar/rrule/occurrence.rb', line 128 def <=>(other) return nil unless other.respond_to? :start_time return nil unless other.start_time.is_a?(ActiveSupport::TimeWithZone) start_compare = @start_time <=> other.start_time return start_compare unless start_compare.zero? return 0 unless other.respond_to? :end_time return 0 unless other.end_time.is_a?(ActiveSupport::TimeWithZone) @end_time <=> other.end_time end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Returns true if the Occurrence can respond to the given method, that is, the base component responds to the given method.
111 112 113 114 115 116 117 118 119 |
# File 'lib/icalendar/rrule/occurrence.rb', line 111 def respond_to_missing?(method_name, include_private = false) if method_name.to_s[-1, 1] == '=' # do not allow to set attributes super ## throws no method error else # delegate all read requests to the base component base_component.respond_to?(method_name, include_private) end end |
#time_zone ⇒ ActiveSupport::TimeZone
Returns the timezone used in this component.
101 102 103 |
# File 'lib/icalendar/rrule/occurrence.rb', line 101 def time_zone base_component.component_timezone end |