addressable 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -89,8 +89,8 @@ returning nil if libidn can‘t be used.
89
89
  <h3 class="section-bar">Methods</h3>
90
90
 
91
91
  <div class="name-list">
92
- <a href="#M000054">to_ascii</a>&nbsp;&nbsp;
93
- <a href="#M000055">to_unicode</a>&nbsp;&nbsp;
92
+ <a href="#M000055">to_ascii</a>&nbsp;&nbsp;
93
+ <a href="#M000056">to_unicode</a>&nbsp;&nbsp;
94
94
  </div>
95
95
  </div>
96
96
 
@@ -112,11 +112,11 @@ returning nil if libidn can&#8216;t be used.
112
112
  <div id="methods">
113
113
  <h3 class="section-bar">Public Class methods</h3>
114
114
 
115
- <div id="method-M000054" class="method-detail">
116
- <a name="M000054"></a>
115
+ <div id="method-M000055" class="method-detail">
116
+ <a name="M000055"></a>
117
117
 
118
118
  <div class="method-heading">
119
- <a href="#M000054" class="method-signature">
119
+ <a href="#M000055" class="method-signature">
120
120
  <span class="method-name">to_ascii</span><span class="method-args">(label)</span>
121
121
  </a>
122
122
  </div>
@@ -126,30 +126,30 @@ returning nil if libidn can&#8216;t be used.
126
126
  Returns the ascii representation of the label.
127
127
  </p>
128
128
  <p><a class="source-toggle" href="#"
129
- onclick="toggleCode('M000054-source');return false;">[Source]</a></p>
130
- <div class="method-source-code" id="M000054-source">
129
+ onclick="toggleCode('M000055-source');return false;">[Source]</a></p>
130
+ <div class="method-source-code" id="M000055-source">
131
131
  <pre>
132
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 991</span>
133
- 991: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_ascii</span>(<span class="ruby-identifier">label</span>)
134
- 992: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">label</span>.<span class="ruby-identifier">nil?</span>
135
- 993: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">use_libidn?</span>
136
- 994: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">IDN</span><span class="ruby-operator">::</span><span class="ruby-constant">Idna</span>.<span class="ruby-identifier">toASCII</span>(<span class="ruby-identifier">label</span>)
137
- 995: <span class="ruby-keyword kw">else</span>
138
- 996: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>,
139
- 997: <span class="ruby-value str">&quot;There is no available pure-ruby implementation. &quot;</span> <span class="ruby-operator">+</span>
140
- 998: <span class="ruby-value str">&quot;Install libidn bindings.&quot;</span>
141
- 999: <span class="ruby-keyword kw">end</span>
142
- 1000: <span class="ruby-keyword kw">end</span>
132
+ <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1074</span>
133
+ 1074: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_ascii</span>(<span class="ruby-identifier">label</span>)
134
+ 1075: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">label</span>.<span class="ruby-identifier">nil?</span>
135
+ 1076: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">use_libidn?</span>
136
+ 1077: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">IDN</span><span class="ruby-operator">::</span><span class="ruby-constant">Idna</span>.<span class="ruby-identifier">toASCII</span>(<span class="ruby-identifier">label</span>)
137
+ 1078: <span class="ruby-keyword kw">else</span>
138
+ 1079: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>,
139
+ 1080: <span class="ruby-value str">&quot;There is no available pure-ruby implementation. &quot;</span> <span class="ruby-operator">+</span>
140
+ 1081: <span class="ruby-value str">&quot;Install libidn bindings.&quot;</span>
141
+ 1082: <span class="ruby-keyword kw">end</span>
142
+ 1083: <span class="ruby-keyword kw">end</span>
143
143
  </pre>
144
144
  </div>
145
145
  </div>
146
146
  </div>
147
147
 
148
- <div id="method-M000055" class="method-detail">
149
- <a name="M000055"></a>
148
+ <div id="method-M000056" class="method-detail">
149
+ <a name="M000056"></a>
150
150
 
151
151
  <div class="method-heading">
152
- <a href="#M000055" class="method-signature">
152
+ <a href="#M000056" class="method-signature">
153
153
  <span class="method-name">to_unicode</span><span class="method-args">(label)</span>
154
154
  </a>
155
155
  </div>
@@ -159,20 +159,20 @@ Returns the ascii representation of the label.
159
159
  Returns the unicode representation of the label.
160
160
  </p>
161
161
  <p><a class="source-toggle" href="#"
162
- onclick="toggleCode('M000055-source');return false;">[Source]</a></p>
163
- <div class="method-source-code" id="M000055-source">
162
+ onclick="toggleCode('M000056-source');return false;">[Source]</a></p>
163
+ <div class="method-source-code" id="M000056-source">
164
164
  <pre>
165
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1003</span>
166
- 1003: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_unicode</span>(<span class="ruby-identifier">label</span>)
167
- 1004: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">label</span>.<span class="ruby-identifier">nil?</span>
168
- 1005: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">use_libidn?</span>
169
- 1006: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">IDN</span><span class="ruby-operator">::</span><span class="ruby-constant">Idna</span>.<span class="ruby-identifier">toUnicode</span>(<span class="ruby-identifier">label</span>)
170
- 1007: <span class="ruby-keyword kw">else</span>
171
- 1008: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>,
172
- 1009: <span class="ruby-value str">&quot;There is no available pure-ruby implementation. &quot;</span> <span class="ruby-operator">+</span>
173
- 1010: <span class="ruby-value str">&quot;Install libidn bindings.&quot;</span>
174
- 1011: <span class="ruby-keyword kw">end</span>
175
- 1012: <span class="ruby-keyword kw">end</span>
165
+ <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1086</span>
166
+ 1086: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_unicode</span>(<span class="ruby-identifier">label</span>)
167
+ 1087: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">label</span>.<span class="ruby-identifier">nil?</span>
168
+ 1088: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">use_libidn?</span>
169
+ 1089: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">IDN</span><span class="ruby-operator">::</span><span class="ruby-constant">Idna</span>.<span class="ruby-identifier">toUnicode</span>(<span class="ruby-identifier">label</span>)
170
+ 1090: <span class="ruby-keyword kw">else</span>
171
+ 1091: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>,
172
+ 1092: <span class="ruby-value str">&quot;There is no available pure-ruby implementation. &quot;</span> <span class="ruby-operator">+</span>
173
+ 1093: <span class="ruby-value str">&quot;Install libidn bindings.&quot;</span>
174
+ 1094: <span class="ruby-keyword kw">end</span>
175
+ 1095: <span class="ruby-keyword kw">end</span>
176
176
  </pre>
177
177
  </div>
178
178
  </div>
@@ -1 +1 @@
1
- Wed Sep 05 00:27:02 -0400 2007
1
+ Wed Sep 05 16:05:51 -0400 2007
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Wed Sep 05 00:26:46 -0400 2007</td>
59
+ <td>Wed Sep 05 13:34:16 -0400 2007</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -69,7 +69,12 @@
69
69
  <div id="contextContent">
70
70
 
71
71
  <div id="description">
72
- <h3><a href="../classes/Addressable.html">Addressable</a> 0.1.0</h3>
72
+ <h3><a href="../classes/Addressable.html">Addressable</a> 0.1.1</h3>
73
+ <pre>
74
+ * updated documentation
75
+ * added URI Template variable extraction
76
+ </pre>
77
+ <h3><a href="../classes/Addressable.html">Addressable</a> 0.1.0</h3>
73
78
  <pre>
74
79
  * initial release
75
80
  * implementation based on RFC 3986, 3987
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Thu Aug 30 13:42:50 -0400 2007</td>
59
+ <td>Wed Sep 05 00:34:58 -0400 2007</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Thu Aug 30 12:05:39 -0400 2007</td>
59
+ <td>Wed Sep 05 13:10:21 -0400 2007</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -75,6 +75,29 @@ the URI implementation that is part of Ruby&#8216;s standard library. It
75
75
  more closely conforms to the relevant RFCs and adds support for IRIs and
76
76
  URI templates.
77
77
  </p>
78
+ <p>
79
+ Example usage:
80
+ </p>
81
+ <pre>
82
+ require 'addressable/uri'
83
+
84
+ uri = Addressable::URI.parse(&quot;http://example.com/path/to/resource/&quot;)
85
+ uri.scheme
86
+ =&gt; &quot;http&quot;
87
+ uri.host
88
+ =&gt; &quot;example.com&quot;
89
+ uri.path
90
+ =&gt; &quot;/path/to/resource/&quot;
91
+
92
+ Addressable::URI.expand_template(&quot;http://example.com/{query}/&quot;, {
93
+ &quot;query&quot; =&gt; &quot;an+example+query&quot;
94
+ })
95
+ =&gt; #&lt;Addressable::URI:0x123456 URI:http://example.com/an+example+query/&gt;
96
+
97
+ uri = Addressable::URI.parse(&quot;http://www.詹姆斯.com/&quot;)
98
+ uri.normalize
99
+ =&gt; #&lt;Addressable::URI:0x654321 URI:http://www.xn--8ws00zhy3a.com/&gt;
100
+ </pre>
78
101
 
79
102
  </div>
80
103
 
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Wed Sep 05 00:19:13 -0400 2007</td>
59
+ <td>Wed Sep 05 16:01:22 -0400 2007</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -73,6 +73,7 @@
73
73
  <h3 class="section-bar">Required files</h3>
74
74
 
75
75
  <div class="name-list">
76
+ addressable/version&nbsp;&nbsp;
76
77
  rubygems&nbsp;&nbsp;
77
78
  idn&nbsp;&nbsp;
78
79
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Thu Aug 30 13:43:14 -0400 2007</td>
59
+ <td>Wed Sep 05 14:18:58 -0400 2007</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -20,61 +20,62 @@
20
20
  <div id="index">
21
21
  <h1 class="section-bar">Methods</h1>
22
22
  <div id="index-entries">
23
- <a href="classes/Addressable/URI.html#M000039">+ (Addressable::URI)</a><br />
24
- <a href="classes/Addressable/URI.html#M000048">== (Addressable::URI)</a><br />
25
- <a href="classes/Addressable/URI.html#M000047">=== (Addressable::URI)</a><br />
26
- <a href="classes/Addressable/URI.html#M000038">absolute? (Addressable::URI)</a><br />
27
- <a href="classes/Addressable/URI.html#M000021">authority (Addressable::URI)</a><br />
28
- <a href="classes/Addressable/URI.html#M000022">authority= (Addressable::URI)</a><br />
29
- <a href="classes/Addressable/URI.html#M000030">basename (Addressable::URI)</a><br />
23
+ <a href="classes/Addressable/URI.html#M000040">+ (Addressable::URI)</a><br />
24
+ <a href="classes/Addressable/URI.html#M000049">== (Addressable::URI)</a><br />
25
+ <a href="classes/Addressable/URI.html#M000048">=== (Addressable::URI)</a><br />
26
+ <a href="classes/Addressable/URI.html#M000039">absolute? (Addressable::URI)</a><br />
27
+ <a href="classes/Addressable/URI.html#M000022">authority (Addressable::URI)</a><br />
28
+ <a href="classes/Addressable/URI.html#M000023">authority= (Addressable::URI)</a><br />
29
+ <a href="classes/Addressable/URI.html#M000031">basename (Addressable::URI)</a><br />
30
30
  <a href="classes/Addressable/URI.html#M000002">convert_path (Addressable::URI)</a><br />
31
- <a href="classes/Addressable/URI.html#M000046">display_uri (Addressable::URI)</a><br />
32
- <a href="classes/Addressable/URI.html#M000050">dup (Addressable::URI)</a><br />
33
- <a href="classes/Addressable/URI.html#M000007">encode (Addressable::URI)</a><br />
34
- <a href="classes/Addressable/URI.html#M000005">encode_segment (Addressable::URI)</a><br />
35
- <a href="classes/Addressable/URI.html#M000049">eql? (Addressable::URI)</a><br />
31
+ <a href="classes/Addressable/URI.html#M000047">display_uri (Addressable::URI)</a><br />
32
+ <a href="classes/Addressable/URI.html#M000051">dup (Addressable::URI)</a><br />
33
+ <a href="classes/Addressable/URI.html#M000008">encode (Addressable::URI)</a><br />
34
+ <a href="classes/Addressable/URI.html#M000006">encode_segment (Addressable::URI)</a><br />
35
+ <a href="classes/Addressable/URI.html#M000050">eql? (Addressable::URI)</a><br />
36
36
  <a href="classes/Addressable/URI.html#M000003">expand_template (Addressable::URI)</a><br />
37
- <a href="classes/Addressable/URI.html#M000031">extname (Addressable::URI)</a><br />
38
- <a href="classes/Addressable/URI.html#M000009">extract (Addressable::URI)</a><br />
39
- <a href="classes/Addressable/URI.html#M000034">fragment (Addressable::URI)</a><br />
40
- <a href="classes/Addressable/URI.html#M000035">fragment= (Addressable::URI)</a><br />
41
- <a href="classes/Addressable/URI.html#M000019">host (Addressable::URI)</a><br />
42
- <a href="classes/Addressable/URI.html#M000020">host= (Addressable::URI)</a><br />
43
- <a href="classes/Addressable/URI.html#M000053">inspect (Addressable::URI)</a><br />
44
- <a href="classes/Addressable/URI.html#M000036">ip_based? (Addressable::URI)</a><br />
45
- <a href="classes/Addressable/URI.html#M000023">ip_based_schemes (Addressable::URI)</a><br />
46
- <a href="classes/Addressable/URI.html#M000004">join (Addressable::URI)</a><br />
47
- <a href="classes/Addressable/URI.html#M000040">merge (Addressable::URI)</a><br />
48
- <a href="classes/Addressable/URI.html#M000041">merge! (Addressable::URI)</a><br />
49
- <a href="classes/Addressable/URI.html#M000010">new (Addressable::URI)</a><br />
50
- <a href="classes/Addressable/URI.html#M000044">normalize (Addressable::URI)</a><br />
51
- <a href="classes/Addressable/URI.html#M000045">normalize! (Addressable::URI)</a><br />
52
- <a href="classes/Addressable/URI.html#M000008">normalized_encode (Addressable::URI)</a><br />
37
+ <a href="classes/Addressable/URI.html#M000032">extname (Addressable::URI)</a><br />
38
+ <a href="classes/Addressable/URI.html#M000010">extract (Addressable::URI)</a><br />
39
+ <a href="classes/Addressable/URI.html#M000004">extract_mapping (Addressable::URI)</a><br />
40
+ <a href="classes/Addressable/URI.html#M000035">fragment (Addressable::URI)</a><br />
41
+ <a href="classes/Addressable/URI.html#M000036">fragment= (Addressable::URI)</a><br />
42
+ <a href="classes/Addressable/URI.html#M000020">host (Addressable::URI)</a><br />
43
+ <a href="classes/Addressable/URI.html#M000021">host= (Addressable::URI)</a><br />
44
+ <a href="classes/Addressable/URI.html#M000054">inspect (Addressable::URI)</a><br />
45
+ <a href="classes/Addressable/URI.html#M000037">ip_based? (Addressable::URI)</a><br />
46
+ <a href="classes/Addressable/URI.html#M000024">ip_based_schemes (Addressable::URI)</a><br />
47
+ <a href="classes/Addressable/URI.html#M000005">join (Addressable::URI)</a><br />
48
+ <a href="classes/Addressable/URI.html#M000041">merge (Addressable::URI)</a><br />
49
+ <a href="classes/Addressable/URI.html#M000042">merge! (Addressable::URI)</a><br />
50
+ <a href="classes/Addressable/URI.html#M000011">new (Addressable::URI)</a><br />
51
+ <a href="classes/Addressable/URI.html#M000045">normalize (Addressable::URI)</a><br />
52
+ <a href="classes/Addressable/URI.html#M000046">normalize! (Addressable::URI)</a><br />
53
+ <a href="classes/Addressable/URI.html#M000009">normalized_encode (Addressable::URI)</a><br />
53
54
  <a href="classes/Addressable/URI.html#M000001">parse (Addressable::URI)</a><br />
54
- <a href="classes/Addressable/URI.html#M000015">password (Addressable::URI)</a><br />
55
- <a href="classes/Addressable/URI.html#M000016">password= (Addressable::URI)</a><br />
56
- <a href="classes/Addressable/URI.html#M000028">path (Addressable::URI)</a><br />
57
- <a href="classes/Addressable/URI.html#M000029">path= (Addressable::URI)</a><br />
58
- <a href="classes/Addressable/URI.html#M000025">port (Addressable::URI)</a><br />
59
- <a href="classes/Addressable/URI.html#M000026">port= (Addressable::URI)</a><br />
60
- <a href="classes/Addressable/URI.html#M000032">query (Addressable::URI)</a><br />
61
- <a href="classes/Addressable/URI.html#M000033">query= (Addressable::URI)</a><br />
62
- <a href="classes/Addressable/URI.html#M000037">relative? (Addressable::URI)</a><br />
63
- <a href="classes/Addressable/URI.html#M000042">route_from (Addressable::URI)</a><br />
64
- <a href="classes/Addressable/URI.html#M000043">route_to (Addressable::URI)</a><br />
65
- <a href="classes/Addressable/URI.html#M000011">scheme (Addressable::URI)</a><br />
66
- <a href="classes/Addressable/URI.html#M000012">scheme= (Addressable::URI)</a><br />
67
- <a href="classes/Addressable/URI.html#M000024">scheme_mapping (Addressable::URI)</a><br />
68
- <a href="classes/Addressable/URI.html#M000027">specified_port (Addressable::URI)</a><br />
69
- <a href="classes/Addressable/URI/IDNA.html#M000054">to_ascii (Addressable::URI::IDNA)</a><br />
70
- <a href="classes/Addressable/URI.html#M000052">to_h (Addressable::URI)</a><br />
71
- <a href="classes/Addressable/URI.html#M000051">to_s (Addressable::URI)</a><br />
72
- <a href="classes/Addressable/URI/IDNA.html#M000055">to_unicode (Addressable::URI::IDNA)</a><br />
73
- <a href="classes/Addressable/URI.html#M000006">unencode_segment (Addressable::URI)</a><br />
74
- <a href="classes/Addressable/URI.html#M000013">user (Addressable::URI)</a><br />
75
- <a href="classes/Addressable/URI.html#M000014">user= (Addressable::URI)</a><br />
76
- <a href="classes/Addressable/URI.html#M000017">userinfo (Addressable::URI)</a><br />
77
- <a href="classes/Addressable/URI.html#M000018">userinfo= (Addressable::URI)</a><br />
55
+ <a href="classes/Addressable/URI.html#M000016">password (Addressable::URI)</a><br />
56
+ <a href="classes/Addressable/URI.html#M000017">password= (Addressable::URI)</a><br />
57
+ <a href="classes/Addressable/URI.html#M000029">path (Addressable::URI)</a><br />
58
+ <a href="classes/Addressable/URI.html#M000030">path= (Addressable::URI)</a><br />
59
+ <a href="classes/Addressable/URI.html#M000026">port (Addressable::URI)</a><br />
60
+ <a href="classes/Addressable/URI.html#M000027">port= (Addressable::URI)</a><br />
61
+ <a href="classes/Addressable/URI.html#M000033">query (Addressable::URI)</a><br />
62
+ <a href="classes/Addressable/URI.html#M000034">query= (Addressable::URI)</a><br />
63
+ <a href="classes/Addressable/URI.html#M000038">relative? (Addressable::URI)</a><br />
64
+ <a href="classes/Addressable/URI.html#M000043">route_from (Addressable::URI)</a><br />
65
+ <a href="classes/Addressable/URI.html#M000044">route_to (Addressable::URI)</a><br />
66
+ <a href="classes/Addressable/URI.html#M000012">scheme (Addressable::URI)</a><br />
67
+ <a href="classes/Addressable/URI.html#M000013">scheme= (Addressable::URI)</a><br />
68
+ <a href="classes/Addressable/URI.html#M000025">scheme_mapping (Addressable::URI)</a><br />
69
+ <a href="classes/Addressable/URI.html#M000028">specified_port (Addressable::URI)</a><br />
70
+ <a href="classes/Addressable/URI/IDNA.html#M000055">to_ascii (Addressable::URI::IDNA)</a><br />
71
+ <a href="classes/Addressable/URI.html#M000053">to_h (Addressable::URI)</a><br />
72
+ <a href="classes/Addressable/URI.html#M000052">to_s (Addressable::URI)</a><br />
73
+ <a href="classes/Addressable/URI/IDNA.html#M000056">to_unicode (Addressable::URI::IDNA)</a><br />
74
+ <a href="classes/Addressable/URI.html#M000007">unencode_segment (Addressable::URI)</a><br />
75
+ <a href="classes/Addressable/URI.html#M000014">user (Addressable::URI)</a><br />
76
+ <a href="classes/Addressable/URI.html#M000015">user= (Addressable::URI)</a><br />
77
+ <a href="classes/Addressable/URI.html#M000018">userinfo (Addressable::URI)</a><br />
78
+ <a href="classes/Addressable/URI.html#M000019">userinfo= (Addressable::URI)</a><br />
78
79
  </div>
79
80
  </div>
80
81
  </body>
@@ -21,6 +21,11 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '/..')))
25
+ $:.uniq!
26
+
27
+ require 'addressable/version'
28
+
24
29
  module Addressable
25
30
  # This is an implementation of a URI parser based on RFC 3986.
26
31
  class URI
@@ -197,10 +202,88 @@ module Addressable
197
202
 
198
203
  result.gsub!(/\{#{Regexp.escape(name)}\}/, transformed_value)
199
204
  end
200
- result.gsub!(/\{[#{CharacterClasses::UNRESERVED}]+\}/, "")
205
+ result.gsub!(
206
+ /\{[#{Addressable::URI::CharacterClasses::UNRESERVED}]+\}/, "")
201
207
  return Addressable::URI.parse(result)
202
208
  end
203
209
 
210
+ # Extracts a mapping from the URI using a URI Template pattern.
211
+ # Returns nil if the pattern doesn't match the URI.
212
+ #
213
+ # An optional processor object may be supplied. The object should
214
+ # respond to either the :restore or :match messages or both.
215
+ # The :restore method should take two parameters: :name and :value.
216
+ # The :restore method should reverse any transformations that have been
217
+ # performed on the value to ensure a valid URI. The :match method
218
+ # should take a single parameter: :name. The :match method should
219
+ # return a String containing a regular expression capture group for
220
+ # matching on that particular variable. The default value is ".*".
221
+ #
222
+ # An example:
223
+ #
224
+ # class ExampleProcessor
225
+ # def self.restore(name, value)
226
+ # return value.gsub(/\+/, " ") if name == "query"
227
+ # return value
228
+ # end
229
+ #
230
+ # def self.match(name)
231
+ # return ".*?" if name == "first"
232
+ # return ".*"
233
+ # end
234
+ # end
235
+ #
236
+ # uri = Addressable::URI.parse(
237
+ # "http://example.com/search/an+example+search+query/")
238
+ # uri.extract_mapping("http://example.com/search/{query}/",
239
+ # ExampleProcessor)
240
+ # => {"query" => "an example search query"}
241
+ #
242
+ # uri = Addressable::URI.parse(
243
+ # "http://example.com/a/b/c/")
244
+ # uri.extract_mapping("http://example.com/{first}/{second}/",
245
+ # ExampleProcessor)
246
+ # => {"first" => "a", "second" => "b/c"}
247
+ def extract_mapping(pattern, processor=nil)
248
+ mapping = {}
249
+ variable_regexp =
250
+ /\{([#{Addressable::URI::CharacterClasses::UNRESERVED}]+)\}/
251
+ variables = pattern.scan(variable_regexp).flatten
252
+ variables.each { |v| mapping[v] = "" }
253
+ escaped_pattern =
254
+ Regexp.escape(pattern).gsub(/\\\{/, "{").gsub(/\\\}/, "}")
255
+ regexp = Regexp.new(escaped_pattern.gsub(variable_regexp) do |v|
256
+ capture_group = "(.*)"
257
+
258
+ if processor != nil
259
+ if processor.respond_to?(:match)
260
+ name = v.scan(variable_regexp).flatten[0]
261
+ capture_group = "(#{processor.match(name)})"
262
+ end
263
+ end
264
+
265
+ capture_group
266
+ end)
267
+ values = self.to_s.scan(regexp).flatten
268
+ if variables.size == values.size
269
+ for i in 0...variables.size
270
+ name = variables[i]
271
+ value = values[i]
272
+
273
+ if processor != nil
274
+ if processor.respond_to?(:restore)
275
+ value = processor.restore(name, value)
276
+ end
277
+ end
278
+
279
+ mapping[name] = value
280
+ end
281
+ return mapping
282
+ else
283
+ return nil
284
+ end
285
+ end
286
+
204
287
  # Joins several uris together.
205
288
  def self.join(*uris)
206
289
  uri_objects = uris.collect do |uri|
@@ -25,7 +25,7 @@ module Addressable
25
25
  module ADDRESSABLE_VERSION #:nodoc:
26
26
  MAJOR = 0
27
27
  MINOR = 1
28
- TINY = 0
28
+ TINY = 1
29
29
 
30
30
  STRING = [MAJOR, MINOR, TINY].join('.')
31
31
  end
@@ -36,6 +36,16 @@ class ExampleProcessor
36
36
  return value.gsub(/ /, "+") if name == "query"
37
37
  return value
38
38
  end
39
+
40
+ def self.restore(name, value)
41
+ return value.gsub(/\+/, " ") if name == "query"
42
+ return value
43
+ end
44
+
45
+ def self.match(name)
46
+ return ".*?" if name == "first"
47
+ return ".*"
48
+ end
39
49
  end
40
50
 
41
51
  context "A completely nil URI" do
@@ -2276,3 +2286,60 @@ context "A mapping that contains values that are already percent-encoded" do
2276
2286
  @mapping).to_s.should == "http://example.com/%257Bb%257D/"
2277
2287
  end
2278
2288
  end
2289
+
2290
+ context "http://example.com/search/an+example+search+query/" do
2291
+ setup do
2292
+ @uri = Addressable::URI.parse(
2293
+ "http://example.com/search/an+example+search+query/")
2294
+ end
2295
+
2296
+ specify "when extracting using the pattern " +
2297
+ "'http://example.com/search/{query}/' with the " +
2298
+ "ExampleProcessor to extract values should have the correct mapping" do
2299
+ @uri.extract_mapping(
2300
+ "http://example.com/search/{query}/", ExampleProcessor
2301
+ ).should == {
2302
+ "query" => "an example search query"
2303
+ }
2304
+ end
2305
+
2306
+ specify "when extracting using a non-matching pattern should return nil" do
2307
+ @uri.extract_mapping(
2308
+ "http://bogus.com/{thingy}/"
2309
+ ).should == nil
2310
+ end
2311
+ end
2312
+
2313
+ context "http://example.com/a/b/c/" do
2314
+ setup do
2315
+ @uri = Addressable::URI.parse(
2316
+ "http://example.com/a/b/c/")
2317
+ end
2318
+
2319
+ specify "when extracting using the pattern " +
2320
+ "'http://example.com/{first}/{second}/' with the " +
2321
+ "ExampleProcessor to extract values should have the correct mapping" do
2322
+ @uri.extract_mapping(
2323
+ "http://example.com/{first}/{second}/", ExampleProcessor
2324
+ ).should == {
2325
+ "first" => "a",
2326
+ "second" => "b/c"
2327
+ }
2328
+ end
2329
+ end
2330
+
2331
+ context "http://example.com/one/spacer/two/" do
2332
+ setup do
2333
+ @uri = Addressable::URI.parse("http://example.com/one/spacer/two/")
2334
+ end
2335
+
2336
+ specify "when extracting using the pattern " +
2337
+ "'http://example.com/{first}/spacer/{second}/' to extract values " +
2338
+ "should have the correct mapping" do
2339
+ @uri.extract_mapping(
2340
+ "http://example.com/{first}/spacer/{second}/").should == {
2341
+ "first" => "one",
2342
+ "second" => "two"
2343
+ }
2344
+ end
2345
+ end