class Icalendar::Component

The body of the iCalendar object consists of a sequence of calendar properties and one or more calendar components. The calendar properties are attributes that apply to the calendar as a whole. The calendar components are collections of properties that express a particular calendar semantic. For example, the calendar component can specify an Event, a Todo, a Journal entry, Timezone information, or Freebusy time information, or an Alarm.

Attributes

name[R]
properties[RW]

Public Class Methods

new(name) click to toggle source
# File lib/icalendar/component.rb, line 46
def initialize(name)
  @name = name
  @components = Hash.new([])
  @properties = {}

  @@logger.info("New #{@name[1,@name.size].capitalize}...")
end

Protected Class Methods

ical_component(*syms) click to toggle source

Make it protected so we can monitor usage…

# File lib/icalendar/component.rb, line 216
def Component.ical_component(*syms)
  hash_accessor :@components, *syms
end
ical_multi_property(property, singular, plural) click to toggle source

Define a set of methods defining a new property, which supports multiple values for the same property name.

# File lib/icalendar/component.rb, line 234
def Component.ical_multi_property(property, singular, plural)
  property = "#{property}".strip.downcase.gsub(/-/, '_')
  plural = "#{plural}".strip.downcase

  # Set this key so the parser knows to use an array for
  # storing this property type.
  @@multi_properties["#{property}"] = true

  generate_multi_getter(property, plural)
  generate_multi_setter(property, plural)
  generate_multi_query(property, plural)
  generate_multi_adder(property, singular)
  generate_multi_remover(property, singular)
end
ical_multiline_property(property, singular, plural) click to toggle source

Define a set of methods defining a new property, which supports multiple values in multiple lines with same property name

# File lib/icalendar/component.rb, line 251
def Component.ical_multiline_property(property, singular, plural)
  @@multiline_properties["#{property}"] = true
  ical_multi_property(property, singular, plural)
end
ical_property(property, alias_name = nil, prop_name = nil) click to toggle source

Define a set of methods supporting a new property

# File lib/icalendar/component.rb, line 221
def Component.ical_property(property, alias_name = nil, prop_name = nil)
  property = "#{property}".strip.downcase
  alias_name = "#{alias_name}".strip.downcase unless alias_name.nil?
  # If a prop_name was given then we use that for the actual storage
  property = "#{prop_name}".strip.downcase unless prop_name.nil?

  generate_getter(property, alias_name)
  generate_setter(property, alias_name)
  generate_query(property, alias_name)
end

Public Instance Methods

add(component)

Add a component to the calendar.

Alias for: add_component
add_component(component) click to toggle source

Add a sub-component to the current component object.

# File lib/icalendar/component.rb, line 55
def add_component(component)
  key = (component.class.to_s.downcase + 's').gsub('icalendar::', '').to_sym

  unless @components.has_key? key
    @components[key] = []
  end

  @components[key] << component
end
Also aliased as: add, add_event, add_todo, add_journal
add_event(component)

Add an event to the calendar.

Alias for: add_component
add_journal(component)

Add a journal item to the calendar.

Alias for: add_component
add_sliced_text(add_to,escaped) click to toggle source
# File lib/icalendar/component.rb, line 168
def add_sliced_text(add_to,escaped)
  escaped = escaped.split('') # split is unicdoe-aware when `$KCODE = 'u'`
  add_to << escaped.slice!(0,MAX_LINE_LENGTH).join << "\r\n " while escaped.length != 0 # shift(MAX_LINE_LENGTH) does not work with ruby 1.8.6
  add_to.gsub!(/ *$/, '')
end
add_todo(component)

Add a todo item to the calendar.

Alias for: add_component
custom_property(name, value) click to toggle source

TODO: Look into the x-property, x-param stuff… This would really only be needed for subclassing to add additional properties to an application using the API.

# File lib/icalendar/component.rb, line 201
def custom_property(name, value)
  @properties[name] = value
end
escape_chars(value) click to toggle source
# File lib/icalendar/component.rb, line 162
def escape_chars(value)
  v = value.gsub("\\", "\\\\").gsub("\r\n", "\n").gsub("\r", "\n").gsub("\n", "\\n").gsub(",", "\\,").gsub(";", "\\;")
  return v
   # return value
end
multi_property?(name) click to toggle source
# File lib/icalendar/component.rb, line 205
def multi_property?(name)
  @@multi_properties.has_key?(name.downcase)
end
multiline_property?(name) click to toggle source
# File lib/icalendar/component.rb, line 209
def multiline_property?(name)
  @@multiline_properties.has_key?(name.downcase)
end
new_uid() click to toggle source

Used to generate unique component ids

# File lib/icalendar/component.rb, line 98
def new_uid
  "#{DateTime.now}_#{rand(999999999)}@#{Socket.gethostname}"
end
print_component() { |+ "END:| ... } click to toggle source

Print this icalendar component

print_parameters(value) click to toggle source

Print the parameters for a specific property.

print_properties() click to toggle source
remove(component)

Remove a component from the calendar.

Alias for: remove_component
remove_component(component) click to toggle source
# File lib/icalendar/component.rb, line 77
def remove_component(component)
  key = (component.class.to_s.downcase + 's').gsub('icalendar::', '').to_sym

  if @components.has_key? key
    @components[key].delete(component)
  end
end
remove_event(component)

Remove an event from the calendar.

Alias for: remove_component
remove_journal(component)

Remove a journal item from the calendar.

Alias for: remove_component
remove_todo(component)

Remove a todo item from the calendar.

Alias for: remove_component
respond_to?(method_name) click to toggle source
Calls superclass method
# File lib/icalendar/component.rb, line 434
def respond_to?(method_name)
  if method_name.to_s.downcase =~ /x_.*/
   true
  else
    super
  end
end
to_ical() click to toggle source

Output in the icalendar format

# File lib/icalendar/component.rb, line 103
def to_ical
  print_component do
    s = ""
    @components.each do |key, comps|
      comps.each { |component| s << component.to_ical }
    end
    s
  end
end