Class: Kawaii::RegexpMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/kawaii/matchers.rb

Overview

Regular expression matcher.

Examples:

Simple regular expression matcher

get /\/users.*/ do ... end

Instance Method Summary (collapse)

Constructor Details

- (RegexpMatcher) initialize(rx)

TODO:

Support parameters based on named capture groups.

Creates a Kawaii::RegexpMatcher

Parameters:

  • rx (Regexp)

    path specification regex



105
106
107
# File 'lib/kawaii/matchers.rb', line 105

def initialize(rx)
  @rx = rx
end

Instance Method Details

- (Match) match(path)

Tries to match the actual path. no match.

Parameters:

  • path (String)

    the actual path from Rack env

Returns:

  • (Match)

    if the beginning of path does match or nil if there is



113
114
115
116
# File 'lib/kawaii/matchers.rb', line 113

def match(path)
  new_path = path.gsub(@rx, '')
  Match.new(new_path) if path != new_path
end