class Vcalendar

Attributes

children[RW]
comp_name[RW]

Private Class Methods

child_class(key, val) click to toggle source
# File lib/vobject/vcalendar/component.rb, line 48
def child_class(key, val)
  base_class = if key == :VTODO
                 Vobject::Component::Vcalendar::ToDo
               elsif key == :VFREEBUSY
                 Vobject::Component::Vcalendar::FreeBusy
               elsif key == :JOURNAL
                 Vobject::Component::Vcalendar::Journal
               elsif key == :STANDARD
                 Vobject::Component::Vcalendar::Timezone::Standard
               elsif key == :DAYLIGHT
                 Vobject::Component::Vcalendar::Timezone::Daylight
               elsif key == :VTIMEZONE
                 Vobject::Component::Vcalendar::Timezone
               elsif key == :VEVENT
                 Vobject::Component::Vcalendar::Event
               elsif key == :VALARM
                 Vobject::Component::Vcalendar::Alarm
               elsif key == :VAVAILABILITY
                 Vobject::Component::Vcalendar::Vavailability
               elsif key == :AVAILABLE
                 Vobject::Component::Vcalendar::Vavailability::Available
               elsif !(val.is_a?(Hash) && !val.has_key?(:value))
                 property_base_class
               else
                 Vobject::Component::Vcalendar
               end
  return base_class if [:CLASS, :OBJECT, :METHOD].include? key
  camelized_key = key.to_s.downcase.split("_").map(&:capitalize).join("")
  base_class.const_get(camelized_key) rescue base_class
end
initialize(key, cs) click to toggle source
# File lib/vobject/vcalendar/component.rb, line 17
def initialize(key, cs)
  # super key, cs
  self.comp_name = key
  raise_invalid_initialization if key != name

  self.children = []
  if cs.is_a?(Array)
    cs.each do |component|
      c = []
      component.each_key do |k|
        val = component[k]
        # iteration of array || hash values is making the value a key!
        next if k.class == Array
        next if k.class == Hash
        cc = child_class(k, val)
        c << cc.new(k, val)
      end
      children << c
    end
  else
    cs.each_key do |k|
      val = cs[k]
      # iteration of array || hash values is making the value a key!
      next if k.class == Array
      next if k.class == Hash
      cc = child_class(k, val)
      children << cc.new(k, val)
    end
  end
end
parse(vcf, strict) click to toggle source
# File lib/vobject/vcalendar/component.rb, line 10
def parse(vcf, strict)
  hash = Vobject::Vcalendar::Grammar.new(strict).parse(vcf)
  comp_name = hash.keys.first

  new comp_name, hash[comp_name], hash[:errors]
end
raise_invalid_parsing() click to toggle source
# File lib/vobject/vcalendar/component.rb, line 81
def raise_invalid_parsing
  raise "Vobject component parse failed"
end