lib/ri_cal/parser.rb in rubyredrick-ri_cal-0.0.2 vs lib/ri_cal/parser.rb in rubyredrick-ri_cal-0.0.3

- old
+ new

@@ -17,11 +17,11 @@ ensure return result end end - def parse_params(string) #:nodoc: + def self.parse_params(string) #:nodoc: if string string.split(";").inject({}) { |result, val| m = /^(.+)=(.+)$/.match(val) invalid unless m result[m[1]] = m[2] @@ -30,15 +30,15 @@ else nil end end - def params_and_value(string) #:nodoc: + def self.params_and_value(string, optional_initial_semi = false) #:nodoc: string = string.sub(/^:/,'') - return ["", string] unless string.match(/^;/) + return [{}, string] unless optional_initial_semi || string.match(/^;/) segments = string.sub(';','').split(":") - return ["", string] if segments.length < 2 + return [{}, string] if segments.length < 2 quote_count = 0 gathering_params = true params = [] values = [] segments.each do |segment| @@ -48,19 +48,19 @@ gathering_params = (1 == quote_count % 2) else values << segment end end - [params.join(":"), values.join(":")] + [parse_params(params.join(":")), values.join(":")] end - + def separate_line(string) #:nodoc: match = string.match(/^([^;:]*)(.*)$/) name = match[1] - params, value = *params_and_value(match[2]) + params, value = *Parser.params_and_value(match[2]) { :name => name, - :params => parse_params(params), + :params => params, :value => value } end def next_separated_line #:nodoc: \ No newline at end of file