This is a hand-written non-validating parser for URI's and ssh/scp almost URI resource descriptors which is intended to be cleaner and simpler than Ruby's standard URI.
I wrote it for two reasons...
-
Ruby's standard URI library doesn't handle ssh/scp resource descriptors, which are the near-to, not quite URI, but commonly used, ssh/scp way of describing a network addressable resource: username:password@host:path. URI's have a scheme at the start, and the path begins with only a forward slash, whereas an ssh/scp resource has no scheme, and the path begins with a colon and a slash. I wanted to be able to handle both.
-
Ruby's standard URI class does too much. It is overblown and untidy. I just want it to break the strings down and that's it. I don't want any scheme interpolation from the port number, nor from the host name, or any other 'smarts'.
Add this line to your application's Gemfile:
gem 'impuri'
And then execute:
$ bundle
Or install it yourself as:
$ gem install impuri
impuri = ImpURI.parse('scheme://user:[email protected]:20/path/to/resource?q=param')
# => an object of class ImpURI
impuri.scheme OR impuri.protocol
# => 'scheme'
impuri.userinfo OR impuri.credentials OR impuri.user_info OR impuri.username_and_password
# => 'user:pass'
impuri.user OR impuri.username
# => 'user'
impuri.pass OR impuri.passwd OR impuri.password
# => 'pass'
impuri.host OR impuri.hostname
# => 'hostname.domain.name'
impuri.port OR impuri.portnumber OR impuri.port_number
# => '20'
impuri.path
# => '/path/to/resource'
impuri.parameter_string
# => 'q=param'
impuri.parameters
# => {'q' => 'param'}
- Fork it ( https://github.com/thoran/ImpURI/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new pull request