Class: RiCal::Component
- Defined in:
- lib/ri_cal/component.rb,
lib/ri_cal/component/todo.rb,
lib/ri_cal/component/alarm.rb,
lib/ri_cal/component/event.rb,
lib/ri_cal/component/journal.rb,
lib/ri_cal/component/calendar.rb,
lib/ri_cal/component/freebusy.rb,
lib/ri_cal/component/timezone.rb,
lib/ri_cal/component/timezone/daylight_period.rb,
lib/ri_cal/component/timezone/standard_period.rb,
lib/ri_cal/component/timezone/timezone_period.rb
Overview
-
©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
Direct Known Subclasses
Alarm, Calendar, Event, Freebusy, Journal, Timezone, Timezone::TimezonePeriod, Todo
Defined Under Namespace
Classes: Alarm, Calendar, ComponentBuilder, Event, Freebusy, Journal, TZInfoTimezone, Timezone, Todo
Instance Attribute Summary collapse
-
#imported ⇒ Object
:nodoc:.
Class Method Summary collapse
-
.entity_name ⇒ Object
:nodoc:.
-
.from_parser(parser, parent) ⇒ Object
:nodoc:.
-
.parse(io) ⇒ Object
:nodoc:.
-
.parse_string(string) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#add_property_date_times_to(required_timezones, property) ⇒ Object
:nodoc:.
-
#add_subcomponent(component) ⇒ Object
:nodoc:.
-
#add_x_property(name, prop) ⇒ Object
Add a n extended property.
-
#alarms ⇒ Object
return an array of Alarm components within this component :nodoc: Alarms may be contained within Events, and Todos.
-
#daylight ⇒ Object
:nodoc:.
-
#default_tzid ⇒ Object
:nodoc:.
-
#entity_name ⇒ Object
:nodoc:.
-
#export(stream = nil) ⇒ Object
Export this single component as an iCalendar component containing only this component and any required additional components (i.e. VTIMEZONES referenced from this component) if stream is nil (the default) then this method will return a string, otherwise stream should be an IO to which the iCalendar file contents will be written.
-
#export_prop_to(export_stream, name, prop) ⇒ Object
:nodoc:.
-
#export_subcomponent_to(export_stream, subcomponent) ⇒ Object
:nodoc:.
-
#export_to(export_stream) ⇒ Object
Export this component to an export stream.
-
#export_x_properties_to(export_stream) ⇒ Object
:nodoc:.
-
#find_timezone(identifier) ⇒ Object
:nodoc:.
-
#imported? ⇒ Boolean
:nodoc:.
-
#initialize(parent = nil, &init_block) ⇒ Component
constructor
:nodoc:.
-
#initialize_copy(original) ⇒ Object
:nodoc:.
-
#last_before_local(period_array, time) ⇒ Object
:nodoc:.
-
#last_before_utc(period_array, time) ⇒ Object
:nodoc:.
-
#last_period(standard, daylight) ⇒ Object
:nodoc:.
-
#method_missing(selector, *args, &b) ⇒ Object
:nodoc:.
-
#parse_subcomponent(parser, line) ⇒ Object
:nodoc:.
-
#process_line(parser, line) ⇒ Object
:nodoc:.
-
#prop_string(prop_name, *properties) ⇒ Object
:nodoc:.
-
#standard ⇒ Object
:nodoc:.
-
#subcomponent_class ⇒ Object
:nodoc:.
-
#subcomponents ⇒ Object
:nodoc:.
-
#time_zone_for(ruby_object) ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
return a string containing the rfc2445 format of the component.
-
#valid? ⇒ Boolean
Predicate to determine if the component is valid according to RFC 2445.
-
#x_properties ⇒ Object
return a hash of any extended properties, (i.e. those with a property name starting with “X-” representing an extension to the RFC 2445 specification).
Constructor Details
#initialize(parent = nil, &init_block) ⇒ Component
:nodoc:
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ri_cal/component.rb', line 37 def initialize(parent=nil, &init_block) #:nodoc: @parent = parent if block_given? if init_block.arity == 1 init_block.call(ComponentBuilder.new(self)) else ComponentBuilder.new(self).instance_eval(&init_block) end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(selector, *args, &b) ⇒ Object
:nodoc:
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/ri_cal/component.rb', line 145 def method_missing(selector, *args, &b) #:nodoc: xprop_candidate = selector.to_s if (match = /^x_(.+)(=?)$/.match(xprop_candidate)) if match[2] == "=" add_x_property("x_#{match[1]}", *args) else x_properties[xprop_candidate] end else super end end |
Instance Attribute Details
#imported ⇒ Object
:nodoc:
35 36 37 |
# File 'lib/ri_cal/component.rb', line 35 def imported @imported end |
Class Method Details
.entity_name ⇒ Object
:nodoc:
151 152 153 |
# File 'lib/ri_cal/component/timezone.rb', line 151 def self.entity_name #:nodoc: "VTIMEZONE" end |
.from_parser(parser, parent) ⇒ Object
:nodoc:
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ri_cal/component.rb', line 76 def self.from_parser(parser, parent) #:nodoc: entity = self.new(parent) entity.imported = true line = parser.next_separated_line while parser.still_in(entity_name, line) entity.process_line(parser, line) line = parser.next_separated_line end entity end |
.parse(io) ⇒ Object
:nodoc:
87 88 89 |
# File 'lib/ri_cal/component.rb', line 87 def self.parse(io) #:nodoc: Parser.new(io).parse end |
.parse_string(string) ⇒ Object
:nodoc:
95 96 97 |
# File 'lib/ri_cal/component.rb', line 95 def self.parse_string(string) #:nodoc: parse(StringIO.new(string)) end |
Instance Method Details
#add_property_date_times_to(required_timezones, property) ⇒ Object
:nodoc:
175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/ri_cal/component.rb', line 175 def add_property_date_times_to(required_timezones, property) #:nodoc: if property if Array === property property.each do |prop| prop.add_date_times_to(required_timezones) end else property.add_date_times_to(required_timezones) end end end |
#add_subcomponent(component) ⇒ Object
:nodoc:
113 114 115 |
# File 'lib/ri_cal/component.rb', line 113 def add_subcomponent(component) #:nodoc: subcomponents[component.entity_name] << component end |
#add_x_property(name, prop) ⇒ Object
Add a n extended property
141 142 143 |
# File 'lib/ri_cal/component.rb', line 141 def add_x_property(name, prop) x_properties[name] = prop end |
#alarms ⇒ Object
return an array of Alarm components within this component :nodoc: Alarms may be contained within Events, and Todos
109 110 111 |
# File 'lib/ri_cal/component.rb', line 109 def alarms subcomponents["VALARM"] end |
#daylight ⇒ Object
:nodoc:
159 160 161 |
# File 'lib/ri_cal/component/timezone.rb', line 159 def daylight #:nodoc: @subcomponents["DAYLIGHT"] end |
#default_tzid ⇒ Object
:nodoc:
48 49 50 51 52 53 54 |
# File 'lib/ri_cal/component.rb', line 48 def default_tzid #:nodoc: if @parent @parent.default_tzid else PropertyValue::DateTime.default_tzid end end |
#entity_name ⇒ Object
:nodoc:
103 104 105 |
# File 'lib/ri_cal/component.rb', line 103 def entity_name #:nodoc: self.class.entity_name end |
#export(stream = nil) ⇒ Object
Export this single component as an iCalendar component containing only this component and any required additional components (i.e. VTIMEZONES referenced from this component) if stream is nil (the default) then this method will return a string, otherwise stream should be an IO to which the iCalendar file contents will be written
228 229 230 231 232 |
# File 'lib/ri_cal/component.rb', line 228 def export(stream=nil) wrapper_calendar = Calendar.new wrapper_calendar.add_subcomponent(self) wrapper_calendar.export(stream) end |
#export_prop_to(export_stream, name, prop) ⇒ Object
:nodoc:
187 188 189 190 191 192 |
# File 'lib/ri_cal/component.rb', line 187 def export_prop_to(export_stream, name, prop) #:nodoc: if prop string = prop_string(name, prop) export_stream.puts(string) if string end end |
#export_subcomponent_to(export_stream, subcomponent) ⇒ Object
:nodoc:
200 201 202 203 204 |
# File 'lib/ri_cal/component.rb', line 200 def export_subcomponent_to(export_stream, subcomponent) #:nodoc: subcomponent.each do |component| component.export_to(export_stream) end end |
#export_to(export_stream) ⇒ Object
Export this component to an export stream
214 215 216 217 218 219 220 221 222 |
# File 'lib/ri_cal/component.rb', line 214 def export_to(export_stream) export_stream.puts("BEGIN:#{entity_name}") export_properties_to(export_stream) export_x_properties_to(export_stream) subcomponents.values do |sub| export_subcomponent_to(export_subcomponent_to, sub) end export_stream.puts("END:#{entity_name}") end |
#export_x_properties_to(export_stream) ⇒ Object
:nodoc:
194 195 196 197 198 |
# File 'lib/ri_cal/component.rb', line 194 def export_x_properties_to(export_stream) #:nodoc: x_properties.each do |name, prop| export_stream.puts("#{name}:#{prop}") end end |
#find_timezone(identifier) ⇒ Object
:nodoc:
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ri_cal/component.rb', line 56 def find_timezone(identifier) #:nodoc: if @parent @parent.find_timezone(identifier) else begin Calendar::TZInfoWrapper.new(TZInfo::Timezone.get(identifier), self) rescue ::TZInfo::InvalidTimezoneIdentifier => ex raise RiCal::InvalidTimezoneIdentifier.invalid_tzinfo_identifier(identifier) end end end |
#imported? ⇒ Boolean
:nodoc:
91 92 93 |
# File 'lib/ri_cal/component.rb', line 91 def imported? #:nodoc: imported end |
#initialize_copy(original) ⇒ Object
:nodoc:
163 164 |
# File 'lib/ri_cal/component.rb', line 163 def initialize_copy(original) #:nodoc: end |
#last_before_local(period_array, time) ⇒ Object
:nodoc:
183 184 185 186 187 188 189 |
# File 'lib/ri_cal/component/timezone.rb', line 183 def last_before_local(period_array, time) #:nodoc: candidates = period_array.map {|period| period.last_before_local(time) } result = candidates.max {|a, b| a.dtstart_property <=> b.dtstart_property} result end |
#last_before_utc(period_array, time) ⇒ Object
:nodoc:
175 176 177 178 179 180 181 |
# File 'lib/ri_cal/component/timezone.rb', line 175 def last_before_utc(period_array, time) #:nodoc: candidates = period_array.map {|period| period.last_before_utc(time) } result = candidates.max {|a, b| a.dtstart_property <=> b.dtstart_property} result end |
#last_period(standard, daylight) ⇒ Object
:nodoc:
163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/ri_cal/component/timezone.rb', line 163 def last_period(standard, daylight) #:nodoc: if standard if daylight standard.dtstart > daylight.dtstart ? standard : daylight else standard end else daylight end end |
#parse_subcomponent(parser, line) ⇒ Object
:nodoc:
117 118 119 |
# File 'lib/ri_cal/component.rb', line 117 def parse_subcomponent(parser, line) #:nodoc: subcomponents[line[:value]] << parser.parse_one(line, self) end |
#process_line(parser, line) ⇒ Object
:nodoc:
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ri_cal/component.rb', line 121 def process_line(parser, line) #:nodoc: if line[:name] == "BEGIN" parse_subcomponent(parser, line) else setter = self.class.property_parser[line[:name]] if setter send(setter, line) else self.add_x_property(line[:name], PropertyValue::Text.new(self, line)) end end end |
#prop_string(prop_name, *properties) ⇒ Object
:nodoc:
166 167 168 169 170 171 172 173 |
# File 'lib/ri_cal/component.rb', line 166 def prop_string(prop_name, *properties) #:nodoc: properties = properties.flatten.compact if properties && !properties.empty? properties.map {|prop| "#{prop_name}#{prop.to_s}"}.join("\n") else nil end end |
#standard ⇒ Object
:nodoc:
155 156 157 |
# File 'lib/ri_cal/component/timezone.rb', line 155 def standard #:nodoc: @subcomponents["STANDARD"] end |
#subcomponent_class ⇒ Object
:nodoc:
72 73 74 |
# File 'lib/ri_cal/component.rb', line 72 def subcomponent_class #:nodoc: {} end |
#subcomponents ⇒ Object
:nodoc:
99 100 101 |
# File 'lib/ri_cal/component.rb', line 99 def subcomponents #:nodoc: @subcomponents ||= Hash.new {|h, k| h[k] = []} end |
#time_zone_for(ruby_object) ⇒ Object
:nodoc:
68 69 70 |
# File 'lib/ri_cal/component.rb', line 68 def time_zone_for(ruby_object) #:nodoc: @parent.time_zone_for(ruby_object) #:nodoc: end |
#to_s ⇒ Object
return a string containing the rfc2445 format of the component
207 208 209 210 211 |
# File 'lib/ri_cal/component.rb', line 207 def to_s io = StringIO.new export_to(io) io.string end |
#valid? ⇒ Boolean
Predicate to determine if the component is valid according to RFC 2445
159 160 161 |
# File 'lib/ri_cal/component.rb', line 159 def valid? !mutual_exclusion_violation end |
#x_properties ⇒ Object
return a hash of any extended properties, (i.e. those with a property name starting with “X-” representing an extension to the RFC 2445 specification)
136 137 138 |
# File 'lib/ri_cal/component.rb', line 136 def x_properties @x_properties ||= {} end |