lib/usher/splitter.rb in joshbuddy-usher-0.4.2 vs lib/usher/splitter.rb in joshbuddy-usher-0.4.3

- old
+ new

@@ -17,42 +17,33 @@ class SplitterInstance def initialize(delimiters, split_regex, url_split_regex) @delimiters = delimiters @delimiter_chars = delimiters.collect{|d| d[0]} + @delimiter_chars_map = Hash[*@delimiter_chars.map{|c| [c, c.chr.to_sym]}.flatten] @split_regex = split_regex @url_split_regex = url_split_regex end def url_split(path) - parts = [] - ss = StringScanner.new(path) - while !ss.eos? - if part = ss.scan(@url_split_regex) - parts << case part[0] - when *@delimiter_chars - part.to_sym - else - part - end - end - end if path && !path.empty? + parts = path.scan(@url_split_regex) + parts.map!{ |part| @delimiter_chars_map[part[0]] || part} parts end - def split(path, requirements = nil, transformers = nil) + def split(path, requirements = nil) parts = Group.new(:all, nil) ss = StringScanner.new(path) current_group = parts while !ss.eos? part = ss.scan(@split_regex) case part[0] when ?*, ?: type = part.slice!(0).chr.to_sym - current_group << Usher::Route::Variable.new(type, part, requirements && requirements[part.to_sym], transformers && transformers[part.to_sym]) + current_group << Usher::Route::Variable.new(type, part, requirements && requirements[part.to_sym]) when ?{ - pattern = '^' + pattern = '' count = 1 variable = ss.scan(/[:\*]([^,]+),/) until count.zero? regex_part = ss.scan(/\{|\}|[^\{\}]+/) case regex_part[0] @@ -61,15 +52,15 @@ when ?} count -= 1 end pattern << regex_part end - pattern[pattern.size - 1] = ?$ + pattern.slice!(pattern.length - 1) regex = Regexp.new(pattern) if variable variable_type = variable.slice!(0).chr.to_sym variable_name = variable[0, variable.size - 1].to_sym - current_group << Usher::Route::Variable.new(variable_type, variable_name, requirements && requirements[variable_name], transformers && transformers[variable_name], regex) + current_group << Usher::Route::Variable.new(variable_type, variable_name, requirements && requirements[variable_name], regex) else current_group << regex end when ?( new_group = Group.new(:any, current_group) \ No newline at end of file