lib/utopia/path/matcher.rb
# This is a path prefix matching algorithm. The pattern is an array of String, Symbol, Regexp, or nil. The path is an array of String.
This is a path prefix matching algorithm. The pattern is an array of String, Symbol, Regexp, or nil. The path is an array of String.
This is a path prefix matching algorithm . The pattern is an array of String Symbol Regexp or nil . The path is an array of String .
def match(path)
				components = path.to_a
				return nil if components.size < @patterns.size
				named_parts = {}
				@patterns.each_with_index do |(key, pattern), index|
					component = components[index]
					if pattern.is_a? Class
						return nil unless value = coerce(pattern, component)
						named_parts[key] = value
					elsif pattern
						if result = pattern.match(component)
							named_parts[key] = result
						else
							return nil
						end
					else
						named_parts[key] = component
					end
				end
				return MatchData.new(named_parts, components[@patterns.size..-1])
			end
def match ( path ) components = path . to_a return nil if components . size < @patterns . size named_parts = { } @patterns . each_with_index do | ( key , pattern ) , index | component = components [ index ] if pattern . is_a? Class return nil unless value = coerce ( pattern , component ) named_parts [ key ] = value elsif pattern if result = pattern . match ( component ) named_parts [ key ] = result else return nil end else named_parts [ key ] = component end end return MatchData . new ( named_parts , components [ @patterns . size .. - 1 ] ) end
This is a path prefix matching algorithm.
This is a path prefix matching algorithm .
# Can't possibly match if not enough components: # Try to match each component against the pattern: # Couldn't match: # Ignore this part:
path