intertwingly

It’s just data

Addressable


Installation:

sudo apt-get install libidn11-dev
sudo gem install idn addressable

Usage:

require 'addressable/uri'

# URI Templates
uri = Addressable::URI.expand_template("http://example.com/?q={query}", {
 "query" => "an example query"
})
puts uri
http://example.com/?q=an%20example%20query

# heuristic_parse / normalize
uri = Addressable::URI.heuristic_parse('http:///example.com/"')
puts uri.normalize
http://example.com/%22

# extract_mapping
uri = Addressable::URI.parse('http://intertwingly.net/blog/2007/12/21/foo')
p uri.extract_mapping('http://{host}/blog/{date}/{slug}')
{"slug"=>"foo", "date"=>"2007/12/21", "host"=>"intertwingly.net"}

# IRI
uri = Addressable::URI.parse("http://www.詹姆斯.com/")
puts uri.normalize
http://www.xn--8ws00zhy3a.com/