Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 88 lines (68 sloc) 2.664 kb
e73b2e4 @sporkmonger Updated documentation to use Markdown.
authored
1 # Addressable
2
3 <dl>
4 <dt>Homepage</dt><dd><a href="http://addressable.rubyforge.org/">addressable.rubyforge.org</a></dd>
5 <dt>Author</dt><dd><a href="mailto:bob@sporkmonger.com">Bob Aman</a></dd>
6 <dt>Copyright</dt><dd>Copyright © 2010 Bob Aman</dd>
7 <dt>License</dt><dd>Apache 2.0</dd>
8 </dl>
9
d4eabc4 @sporkmonger Added build and dependency statuses to README.
authored
10 [![Build Status](https://secure.travis-ci.org/sporkmonger/addressable.png)](http://travis-ci.org/sporkmonger/addressable)
11 [![Dependency Status](https://gemnasium.com/sporkmonger/addressable.png)](https://gemnasium.com/sporkmonger/addressable)
12
e73b2e4 @sporkmonger Updated documentation to use Markdown.
authored
13 # Description
14
15 Addressable is a replacement for the URI implementation that is part of
43c448d Updated README to be more clear about which RFCs are supported.
Bob Aman authored
16 Ruby's standard library. It more closely conforms to RFC 3986, RFC 3987, and
17 RFC 6570 (level 4), additionally providing support for IRIs and URI templates.
e73b2e4 @sporkmonger Updated documentation to use Markdown.
authored
18
19 # Reference
20
21 - {Addressable::URI}
22 - {Addressable::Template}
242f326 @therabidbanana Readme updates, fix for bogus values
therabidbanana authored
23 - {Addressable::UriTemplate}
e73b2e4 @sporkmonger Updated documentation to use Markdown.
authored
24
25 # Example usage
26
27 require "addressable/uri"
28
29 uri = Addressable::URI.parse("http://example.com/path/to/resource/")
30 uri.scheme
31 #=> "http"
32 uri.host
33 #=> "example.com"
34 uri.path
35 #=> "/path/to/resource/"
36
37 uri = Addressable::URI.parse("http://www.詹姆斯.com/")
38 uri.normalize
39 #=> #<Addressable::URI:0xc9a4c8 URI:http://www.xn--8ws00zhy3a.com/>
40
41 require "addressable/template"
42
43 template = Addressable::Template.new("http://example.com/{-list|+|query}/")
44 template.expand({
45 "query" => "an example query".split(" ")
46 })
47 #=> #<Addressable::URI:0xc9d95c URI:http://example.com/an+example+query/>
48
49 template = Addressable::Template.new(
50 "http://example.com/{-join|&|one,two,three}/"
51 )
52 template.partial_expand({"one" => "1", "three" => 3}).pattern
53 #=> "http://example.com/?one=1{-prefix|&two=|two}&three=3"
54
55 template = Addressable::Template.new(
56 "http://{host}/{-suffix|/|segments}?{-join|&|one,two,bogus}\#{fragment}"
57 )
242f326 @therabidbanana Readme updates, fix for bogus values
therabidbanana authored
58 template2 = Addressable::UriTemplate.new(
59 "http://{host}{/segments}/{?one,two,bogus}{#fragment}"
60 )
e73b2e4 @sporkmonger Updated documentation to use Markdown.
authored
61 uri = Addressable::URI.parse(
62 "http://example.com/a/b/c/?one=1&two=2#foo"
63 )
64 template.extract(uri)
242f326 @therabidbanana Readme updates, fix for bogus values
therabidbanana authored
65 template2.extract(uri)
e73b2e4 @sporkmonger Updated documentation to use Markdown.
authored
66 #=>
67 # {
68 # "host" => "example.com",
69 # "segments" => ["a", "b", "c"],
70 # "one" => "1",
71 # "two" => "2",
72 # "fragment" => "foo"
73 # }
74
75 # Install
76
21885b1 @sporkmonger Added note about compatibility issues with native IDN support.
authored
77 $ sudo gem install addressable
e73b2e4 @sporkmonger Updated documentation to use Markdown.
authored
78
79 You may optionally turn on native IDN support by installing libidn and the
80 idn gem:
81
21885b1 @sporkmonger Added note about compatibility issues with native IDN support.
authored
82 $ sudo apt-get install idn # Debian/Ubuntu
83 $ sudo brew install libidn # OS X
84 $ sudo gem install idn
85
86 **NOTE:** Native IDN support appears to be broken in Ruby 1.9.x. The IDN gem
87 hasn't been updated in years.
Something went wrong with that request. Please try again.