Project

url_regexp

0.0
No commit activity in last 3 years
No release in over 3 years
Generate regular expression for URL
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.8
< 13, >= 10.0
< 4, >= 3.0
~> 0.47
~> 0.12
~> 0.8
 Project Readme

url_regexp

Gem Version Dependency Status Build Status Coverage Status Code Climate

Installation

Add the url_regexp gem to your Gemfile.

gem "url_regexp"

And run bundle install.

Usage

e.g.

root = UrlRegexp::Root.new
root.append('http://www.example.com/foo/bar')
root.to_regexp
# => /^http:\/\/www\.example\.com\/foo\/bar([?#]|$)/
root.append('http://www.example.com/foo/bar/wow')
root.to_regexp
# => /^http:\/\/www\.example\.com\/foo\/bar(\/wow)?([?#]|$)/
root.append('http://www.example.com/boo/bar')
root.to_regexp
# => /^http:\/\/www\.example\.com\/(foo\/bar(\/wow)?|boo\/bar)([?#]|$)/
root.append('http://www.example.com/boo/bar/wow')
root.to_regexp
# => /^http:\/\/www\.example\.com\/(foo|boo)\/bar(\/wow)?([?#]|$)/

Options

wildcard_threshold (default: 5)

You can change the threshold to group paths as wildcard.

root = UrlRegexp::Root.new(wildcard_threshold: 2)
root.append('http://www.example.com/foo')
root.to_regexp
# => /^http:\/\/www\.example\.com\/foo([?#]|$)/
root.append('http://www.example.com/bar')
root.to_regexp
# => /^http:\/\/www\.example\.com\/(foo|bar)([?#]|$)/
root.append('http://www.example.com/wow')
root.to_regexp
# => /^http:\/\/www\.example\.com\/([^#?]*)([?#]|$)/

Test

bundle exec rake

It will execute rspec and rubocop.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright

Copyright (c) 2016 Daisuke Taniwaki. See LICENSE for details.