Class: RiCal::Component::Calendar

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

Overview

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:



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

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:



6
7
8
# File 'lib/ri_cal/component/calendar.rb', line 6

def tz_source
  @tz_source
end

Class Method Details

.entity_nameObject

:nodoc:



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

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

Instance Method Details

#add_subcomponent(component) ⇒ Object

add an event to the calendar



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

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



50
51
52
# File 'lib/ri_cal/component/calendar.rb', line 50

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



56
57
58
# File 'lib/ri_cal/component/calendar.rb', line 56

def default_tzid=(value)
  @default_tzid=value
end

#eventsObject

return an array of event components contained within this Calendar



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

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



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/ri_cal/component/calendar.rb', line 228

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:



35
36
37
38
39
40
41
# File 'lib/ri_cal/component/calendar.rb', line 35

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

#export_required_timezones(export_stream) ⇒ Object

:nodoc:



158
159
160
# File 'lib/ri_cal/component/calendar.rb', line 158

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

#find_timezone(identifier) ⇒ Object

:nodoc:



144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ri_cal/component/calendar.rb', line 144

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



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

def freebusys
  subcomponents["VFREEBUSY"]
end

#journalsObject

return an array of journal components contained within this Calendar



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

def journals
  subcomponents["VJOURNAL"]
end

#prodid_property_from_string(line) ⇒ Object

:nodoc:



43
44
45
46
47
# File 'lib/ri_cal/component/calendar.rb', line 43

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

#required_timezonesObject

:nodoc:



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

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

#subcomponent_classObject

:nodoc:



25
26
27
28
29
30
31
32
33
# File 'lib/ri_cal/component/calendar.rb', line 25

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



106
107
108
# File 'lib/ri_cal/component/calendar.rb', line 106

def timezones
  subcomponents["VTIMEZONE"]
end

#todosObject

return an array of todo components contained within this Calendar



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

def todos
  subcomponents["VTODO"]
end

#tz_info_source?Boolean

:nodoc:

Returns:

  • (Boolean)


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

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