lib/ri_cal/parser.rb in ri_cal-0.7.7 vs lib/ri_cal/parser.rb in ri_cal-0.8.0

- old
+ new

@@ -1,10 +1,11 @@ module RiCal #- ©2009 Rick DeNatale #- All rights reserved. Refer to the file README.txt for the license # class Parser # :nodoc: + attr_reader :last_line_str #:nodoc: def next_line #:nodoc: result = nil begin result = buffer_or_line @buffer = nil @@ -57,15 +58,16 @@ end def separate_line(string) #:nodoc: match = string.match(/^([^;:]*)(.*)$/) name = match[1] + @last_line_str = string params, value = *Parser.params_and_value(match[2]) { :name => name, :params => params, - :value => value + :value => value, } end def next_separated_line #:nodoc: line = next_line @@ -95,11 +97,12 @@ def parse #:nodoc: result = [] while start_line = next_line @parent_stack = [] - result << parse_one(start_line, nil) + component = parse_one(start_line, nil) + result << component if component end result end # TODO: Need to parse non-standard component types (iana-token or x-name) @@ -110,30 +113,31 @@ first_line = start else first_line = separate_line(start) end invalid unless first_line[:name] == "BEGIN" - result = case first_line[:value] + entity_name = first_line[:value] + result = case entity_name when "VCALENDAR" - RiCal::Component::Calendar.from_parser(self, parent_component) + RiCal::Component::Calendar.from_parser(self, parent_component, entity_name) when "VEVENT" - RiCal::Component::Event.from_parser(self, parent_component) + RiCal::Component::Event.from_parser(self, parent_component, entity_name) when "VTODO" - RiCal::Component::Todo.from_parser(self, parent_component) + RiCal::Component::Todo.from_parser(self, parent_component, entity_name) when "VJOURNAL" - RiCal::Component::Journal.from_parser(self, parent_component) + RiCal::Component::Journal.from_parser(self, parent_component, entity_name) when "VFREEBUSY" - RiCal::Component::Freebusy.from_parser(self, parent_component) + RiCal::Component::Freebusy.from_parser(self, parent_component, entity_name) when "VTIMEZONE" - RiCal::Component::Timezone.from_parser(self, parent_component) + RiCal::Component::Timezone.from_parser(self, parent_component, entity_name) when "VALARM" - RiCal::Component::Alarm.from_parser(self, parent_component) + RiCal::Component::Alarm.from_parser(self, parent_component, entity_name) when "DAYLIGHT" - RiCal::Component::Timezone::DaylightPeriod.from_parser(self, parent_component) + RiCal::Component::Timezone::DaylightPeriod.from_parser(self, parent_component, entity_name) when "STANDARD" - RiCal::Component::Timezone::StandardPeriod.from_parser(self, parent_component) + RiCal::Component::Timezone::StandardPeriod.from_parser(self, parent_component, entity_name) else - invalid + RiCal::Component::NonStandard.from_parser(self, parent_component, entity_name) end @parent_stack.pop result end end \ No newline at end of file