Class: Parameterised::Paths::Path
- Inherits:
-
Object
- Object
- Parameterised::Paths::Path
- Defined in:
- lib/parameterised/paths/path.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ Path
constructor
Path constructor.
-
#match(path) ⇒ PathMatch|nil
Attempts to match a path against our parameterised path.
Constructor Details
#initialize(path) ⇒ Path
Path constructor
11 12 13 14 15 16 |
# File 'lib/parameterised/paths/path.rb', line 11 def initialize(path) @original_path = path @parameterised = false @params = [] @path = parse_path(path) end |
Instance Method Details
#match(path) ⇒ PathMatch|nil
Attempts to match a path against our parameterised path
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/parameterised/paths/path.rb', line 24 def match(path) path = normalise_path(path) unless @path.is_a?(Regexp) return @path == path ? PathMatch.new(@original_path) : nil end match = path.match(@path) return nil if match.nil? pos = 0 param = {} match.captures.each do |capture| capture.sub!('/', '') param[@params[pos]] = capture pos += 1 end PathMatch.new(@original_path, param) end |