Class: RiCal::Component::Calendar

Inherits:
RiCal::Component show all
Includes:
Properties::Calendar
Defined in:
lib/ri_cal/component/calendar.rb

Overview

  • ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license

to see the property accessing methods for this class see the RiCal::Properties::Calendar module

Defined Under Namespace

Classes: FoldingStream, TZInfoWrapper, TimezoneID

Instance Attribute Summary collapse

Attributes inherited from RiCal::Component

#imported

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Properties::Calendar

#==, #add_date_times_to, #calscale, #calscale_property, #calscale_property_from_string, #icalendar_method, #icalendar_method=, included, #initialize_copy, #method_property, #method_property=, #method_property_from_string, #mutual_exclusion_violation, #prodid, #prodid=, #prodid_property, #prodid_property=, #version, #version_property, #version_property_from_string

Methods inherited from RiCal::Component

#add_property_date_times_to, #add_x_property, #alarms, #daylight, #entity_name, #export_prop_to, #export_subcomponent_to, #export_x_properties_to, from_parser, #imported?, #initialize_copy, #last_before_local, #last_before_utc, #last_period, #method_missing, parse, parse_string, #parse_subcomponent, #process_line, #prop_string, #standard, #subcomponents, #time_zone_for, #to_s, #valid?, #x_properties

Constructor Details

#initialize(parent = nil, entity_name = nil, &init_block) ⇒ Calendar

:nodoc:



12
13
14
15
# File 'lib/ri_cal/component/calendar.rb', line 12

def initialize(parent=nil,entity_name = nil, &init_block) #:nodoc:
  @tz_source = 'TZINFO' # Until otherwise told
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RiCal::Component

Instance Attribute Details

#tz_sourceObject (readonly)

:nodoc:



10
11
12
# File 'lib/ri_cal/component/calendar.rb', line 10

def tz_source
  @tz_source
end

Class Method Details

.entity_nameObject

:nodoc:



17
18
19
# File 'lib/ri_cal/component/calendar.rb', line 17

def self.entity_name #:nodoc:
  "VCALENDAR"
end

Instance Method Details

#add_subcomponent(component) ⇒ Object

add an event to the calendar



70
71
72
73
# File 'lib/ri_cal/component/calendar.rb', line 70

def add_subcomponent(component)
  super(component)
  component.add_date_times_to(required_timezones) if tz_info_source?
end

#default_tzidObject

Return the default time zone identifier for this calendar



54
55
56
# File 'lib/ri_cal/component/calendar.rb', line 54

def default_tzid
  @default_tzid || PropertyValue::DateTime.default_tzid
end

#default_tzid=(value) ⇒ Object

Set the default time zone identifier for this calendar To set the default to floating times use a value of :floating



60
61
62
# File 'lib/ri_cal/component/calendar.rb', line 60

def default_tzid=(value)
  @default_tzid=value
end

#eventsObject

return an array of event components contained within this Calendar



65
66
67
# File 'lib/ri_cal/component/calendar.rb', line 65

def events
  subcomponents["VEVENT"]
end

#export(to = nil) ⇒ Object Also known as: export_to

Export this calendar as an iCalendar file. if to is nil (the default) then this method will return a string, otherwise to should be an IO to which the iCalendar file contents will be written



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/ri_cal/component/calendar.rb', line 232

def export(to=nil)
  export_stream = FoldingStream.new(to)
  export_stream.puts("BEGIN:VCALENDAR")
  export_properties_to(export_stream)
  export_x_properties_to(export_stream)
  export_required_timezones(export_stream)
  export_subcomponent_to(export_stream, events)
  export_subcomponent_to(export_stream, todos)
  export_subcomponent_to(export_stream, journals)
  export_subcomponent_to(export_stream, freebusys)
  subcomponents.each do |key, value|
    unless %{VEVENT VTODO VJOURNAL VFREEBUSYS}.include?(key)
      export_subcomponent_to(export_stream, value)
    end
  end
  export_stream.puts("END:VCALENDAR")
  if to
    nil
  else
    export_stream.string
  end
end

#export_properties_to(export_stream) ⇒ Object

:nodoc:



39
40
41
42
43
44
45
# File 'lib/ri_cal/component/calendar.rb', line 39

def export_properties_to(export_stream) # :nodoc:
  prodid_property.params["X-RICAL-TZSOURCE"] = @tz_source
  export_prop_to(export_stream, "PRODID", prodid_property)
  export_prop_to(export_stream, "CALSCALE", calscale_property)
  export_prop_to(export_stream, "VERSION", version_property)
  export_prop_to(export_stream, "METHOD", method_property)
end

#export_required_timezones(export_stream) ⇒ Object

:nodoc:



162
163
164
# File 'lib/ri_cal/component/calendar.rb', line 162

def export_required_timezones(export_stream) # :nodoc:
  required_timezones.export_to(export_stream)
end

#find_timezone(identifier) ⇒ Object

:nodoc:



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/ri_cal/component/calendar.rb', line 148

def find_timezone(identifier)  #:nodoc:
  if tz_info_source?
    begin
      TZInfoWrapper.new(TZInfo::Timezone.get(identifier), self)
    rescue ::TZInfo::InvalidTimezoneIdentifier => ex
      raise RiCal::InvalidTimezoneIdentifier.invalid_tzinfo_identifier(identifier)
    end
  else
    result = timezones.find {|tz| tz.tzid == identifier}
    raise RiCal::InvalidTimezoneIdentifier.not_found_in_calendar(identifier) unless result
    result
  end
end

#freebusysObject

return an array of freebusy components contained within this Calendar



86
87
88
# File 'lib/ri_cal/component/calendar.rb', line 86

def freebusys
  subcomponents["VFREEBUSY"]
end

#journalsObject

return an array of journal components contained within this Calendar



81
82
83
# File 'lib/ri_cal/component/calendar.rb', line 81

def journals
  subcomponents["VJOURNAL"]
end

#prodid_property_from_string(line) ⇒ Object

:nodoc:



47
48
49
50
51
# File 'lib/ri_cal/component/calendar.rb', line 47

def prodid_property_from_string(line) # :nodoc:
  result = super
  @tz_source = prodid_property.params["X-RICAL-TZSOURCE"]
  result
end

#required_timezonesObject

:nodoc:



25
26
27
# File 'lib/ri_cal/component/calendar.rb', line 25

def required_timezones # :nodoc:
  @required_timezones ||=  RequiredTimezones.new
end

#subcomponent_classObject

:nodoc:



29
30
31
32
33
34
35
36
37
# File 'lib/ri_cal/component/calendar.rb', line 29

def subcomponent_class # :nodoc:
  {
    :event => Event,
    :todo  => Todo,
    :journal => Journal,
    :freebusy => Freebusy,
    :timezone => Timezone,
  }
end

#timezonesObject

return an array of timezone components contained within this calendar



110
111
112
# File 'lib/ri_cal/component/calendar.rb', line 110

def timezones
  subcomponents["VTIMEZONE"]
end

#todosObject

return an array of todo components contained within this Calendar



76
77
78
# File 'lib/ri_cal/component/calendar.rb', line 76

def todos
  subcomponents["VTODO"]
end

#tz_info_source?Boolean

:nodoc:

Returns:

  • (Boolean)


21
22
23
# File 'lib/ri_cal/component/calendar.rb', line 21

def tz_info_source? #:nodoc:
  @tz_source == 'TZINFO'
end