addressable 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -553,7 +553,7 @@ span.run100 {
553
553
  </style>
554
554
  </head>
555
555
  <body><h3>C0 code coverage information</h3>
556
- <p>Generated on Thu Dec 13 13:10:50 -0500 2007 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
556
+ <p>Generated on Sat May 03 13:27:45 -0400 2008 with <a href='http://eigenclass.org/hiki/rcov'>rcov 0.8.1.2</a>
557
557
  </p>
558
558
  <hr/>
559
559
  <pre><span class='marked0'>Code reported as executed by Ruby looks like this...
@@ -599,7 +599,7 @@ span.run100 {
599
599
  </tbody>
600
600
  </table>
601
601
  <pre><span class="inferred1"><a name="line1"></a> 1 #--
602
- </span><span class="inferred0"><a name="line2"></a> 2 # Addressable, Copyright (c) 2006-2007 Bob Aman
602
+ </span><span class="inferred0"><a name="line2"></a> 2 # Addressable, Copyright (c) 2006-2008 Bob Aman
603
603
  </span><span class="inferred1"><a name="line3"></a> 3 #
604
604
  </span><span class="inferred0"><a name="line4"></a> 4 # Permission is hereby granted, free of charge, to any person obtaining
605
605
  </span><span class="inferred1"><a name="line5"></a> 5 # a copy of this software and associated documentation files (the
@@ -625,7 +625,7 @@ span.run100 {
625
625
  </span><span class="marked1"><a name="line25"></a>25 module ADDRESSABLE_VERSION #:nodoc:
626
626
  </span><span class="marked0"><a name="line26"></a>26 MAJOR = 1
627
627
  </span><span class="marked1"><a name="line27"></a>27 MINOR = 0
628
- </span><span class="marked0"><a name="line28"></a>28 TINY = 2
628
+ </span><span class="marked0"><a name="line28"></a>28 TINY = 3
629
629
  </span><span class="inferred1"><a name="line29"></a>29
630
630
  </span><span class="marked0"><a name="line30"></a>30 STRING = [MAJOR, MINOR, TINY].join('.')
631
631
  </span><span class="inferred1"><a name="line31"></a>31 end
@@ -93,7 +93,7 @@ module Addressable
93
93
  host = authority.gsub(/^([^\[\]]*)@/, "").gsub(/:([^:@\[\]]*?)$/, "")
94
94
  port = authority.scan(/:([^:@\[\]]*?)$/).flatten[0]
95
95
  end
96
- if port == nil || port == ""
96
+ if port == ""
97
97
  port = nil
98
98
  end
99
99
 
@@ -1070,6 +1070,12 @@ module Addressable
1070
1070
  return false unless uri.kind_of?(self.class)
1071
1071
  return self.to_s == uri.to_s
1072
1072
  end
1073
+
1074
+ # Returns a hash value that will make a URI equivalent to its normalized
1075
+ # form.
1076
+ def hash
1077
+ return (self.normalize.to_s.hash * -1)
1078
+ end
1073
1079
 
1074
1080
  # Clones the URI object.
1075
1081
  def dup
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Addressable, Copyright (c) 2006-2007 Bob Aman
2
+ # Addressable, Copyright (c) 2006-2008 Bob Aman
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -25,7 +25,7 @@ module Addressable
25
25
  module ADDRESSABLE_VERSION #:nodoc:
26
26
  MAJOR = 1
27
27
  MINOR = 0
28
- TINY = 2
28
+ TINY = 3
29
29
 
30
30
  STRING = [MAJOR, MINOR, TINY].join('.')
31
31
  end
@@ -610,6 +610,18 @@ describe Addressable::URI, " when parsed from " +
610
610
  it "should be identical to its duplicate" do
611
611
  @uri.should == @uri.dup
612
612
  end
613
+
614
+ it "should have the same hash as its duplicate" do
615
+ @uri.hash.should == @uri.dup.hash
616
+ end
617
+
618
+ it "should have a different hash from its equivalent String value" do
619
+ @uri.hash.should_not == @uri.to_s.hash
620
+ end
621
+
622
+ it "should have the same hash as an equivalent URI" do
623
+ @uri.hash.should == Addressable::URI.parse("http://example.com:80/").hash
624
+ end
613
625
  end
614
626
 
615
627
  describe Addressable::URI, " when parsed from " +
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addressable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
5
- platform: ""
4
+ version: 1.0.3
5
+ platform: ruby
6
6
  authors:
7
7
  - Bob Aman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2007-12-13 00:00:00 -05:00
12
+ date: 2008-05-03 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -46,31 +46,10 @@ files:
46
46
  - spec/addressable/uri_spec.rb
47
47
  - spec/data
48
48
  - spec/data/rfc3986.txt
49
- - doc/classes
50
- - doc/classes/Addressable
51
- - doc/classes/Addressable/URI
52
- - doc/classes/Addressable/URI/CharacterClasses.html
53
- - doc/classes/Addressable/URI/IDNA.html
54
- - doc/classes/Addressable/URI/InvalidOptionError.html
55
- - doc/classes/Addressable/URI/InvalidTemplateValue.html
56
- - doc/classes/Addressable/URI/InvalidURIError.html
57
- - doc/classes/Addressable/URI.html
58
- - doc/classes/Addressable.html
59
- - doc/created.rid
60
- - doc/files
61
- - doc/files/CHANGELOG.html
62
- - doc/files/lib
63
- - doc/files/lib/addressable
64
- - doc/files/lib/addressable/uri_rb.html
65
- - doc/files/lib/addressable/version_rb.html
66
- - doc/files/LICENSE.html
67
- - doc/files/README.html
68
- - doc/fr_class_index.html
69
- - doc/fr_file_index.html
70
- - doc/fr_method_index.html
71
- - doc/index.html
72
- - doc/rdoc-style.css
73
- - specdoc/index.html
49
+ - coverage/-Library-Ruby-Gems-1_8-gems-rcov-0_8_1_2_0-lib-rcov_rb.html
50
+ - coverage/-Library-Ruby-Gems-1_8-gems-rspec-1_1_3-bin-spec.html
51
+ - coverage/-Library-Ruby-Gems-1_8-gems-rspec-1_1_3-lib-spec_rb.html
52
+ - coverage/-Library-Ruby-Gems-1_8-gems-rspec-1_1_3-plugins-mock_frameworks-rspec_rb.html
74
53
  - coverage/index.html
75
54
  - coverage/lib-addressable-uri_rb.html
76
55
  - coverage/lib-addressable-version_rb.html
@@ -101,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
80
  requirements: []
102
81
 
103
82
  rubyforge_project: addressable
104
- rubygems_version: 0.9.5
83
+ rubygems_version: 1.0.1
105
84
  signing_key:
106
85
  specification_version: 2
107
86
  summary: URI Implementation
@@ -1,115 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Module: Addressable</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td><strong>Module</strong></td>
53
- <td class="class-name-in-header">Addressable</td>
54
- </tr>
55
- <tr class="top-aligned-row">
56
- <td><strong>In:</strong></td>
57
- <td>
58
- <a href="../files/lib/addressable/uri_rb.html">
59
- lib/addressable/uri.rb
60
- </a>
61
- <br />
62
- <a href="../files/lib/addressable/version_rb.html">
63
- lib/addressable/version.rb
64
- </a>
65
- <br />
66
- </td>
67
- </tr>
68
-
69
- </table>
70
- </div>
71
- <!-- banner header -->
72
-
73
- <div id="bodyContent">
74
-
75
-
76
-
77
- <div id="contextContent">
78
-
79
-
80
-
81
- </div>
82
-
83
-
84
- </div>
85
-
86
-
87
- <!-- if includes -->
88
-
89
- <div id="section">
90
-
91
- <div id="class-list">
92
- <h3 class="section-bar">Classes and Modules</h3>
93
-
94
- Class <a href="Addressable/URI.html" class="link">Addressable::URI</a><br />
95
-
96
- </div>
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
- <!-- if method_list -->
105
-
106
-
107
- </div>
108
-
109
-
110
- <div id="validator-badges">
111
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
112
- </div>
113
-
114
- </body>
115
- </html>
@@ -1,2509 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Class: Addressable::URI</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td><strong>Class</strong></td>
53
- <td class="class-name-in-header">Addressable::URI</td>
54
- </tr>
55
- <tr class="top-aligned-row">
56
- <td><strong>In:</strong></td>
57
- <td>
58
- <a href="../../files/lib/addressable/uri_rb.html">
59
- lib/addressable/uri.rb
60
- </a>
61
- <br />
62
- </td>
63
- </tr>
64
-
65
- <tr class="top-aligned-row">
66
- <td><strong>Parent:</strong></td>
67
- <td>
68
- Object
69
- </td>
70
- </tr>
71
- </table>
72
- </div>
73
- <!-- banner header -->
74
-
75
- <div id="bodyContent">
76
-
77
-
78
-
79
- <div id="contextContent">
80
-
81
- <div id="description">
82
- <p>
83
- This is an implementation of a <a href="URI.html">URI</a> parser based on
84
- RFC 3986, 3987.
85
- </p>
86
-
87
- </div>
88
-
89
-
90
- </div>
91
-
92
- <div id="method-list">
93
- <h3 class="section-bar">Methods</h3>
94
-
95
- <div class="name-list">
96
- <a href="#M000041">+</a>&nbsp;&nbsp;
97
- <a href="#M000052">==</a>&nbsp;&nbsp;
98
- <a href="#M000051">===</a>&nbsp;&nbsp;
99
- <a href="#M000040">absolute?</a>&nbsp;&nbsp;
100
- <a href="#M000023">authority</a>&nbsp;&nbsp;
101
- <a href="#M000024">authority=</a>&nbsp;&nbsp;
102
- <a href="#M000032">basename</a>&nbsp;&nbsp;
103
- <a href="#M000003">convert_path</a>&nbsp;&nbsp;
104
- <a href="#M000050">display_uri</a>&nbsp;&nbsp;
105
- <a href="#M000054">dup</a>&nbsp;&nbsp;
106
- <a href="#M000009">encode</a>&nbsp;&nbsp;
107
- <a href="#M000007">encode_segment</a>&nbsp;&nbsp;
108
- <a href="#M000053">eql?</a>&nbsp;&nbsp;
109
- <a href="#M000004">expand_template</a>&nbsp;&nbsp;
110
- <a href="#M000033">extname</a>&nbsp;&nbsp;
111
- <a href="#M000011">extract</a>&nbsp;&nbsp;
112
- <a href="#M000005">extract_mapping</a>&nbsp;&nbsp;
113
- <a href="#M000036">fragment</a>&nbsp;&nbsp;
114
- <a href="#M000037">fragment=</a>&nbsp;&nbsp;
115
- <a href="#M000002">heuristic_parse</a>&nbsp;&nbsp;
116
- <a href="#M000021">host</a>&nbsp;&nbsp;
117
- <a href="#M000022">host=</a>&nbsp;&nbsp;
118
- <a href="#M000057">inspect</a>&nbsp;&nbsp;
119
- <a href="#M000038">ip_based?</a>&nbsp;&nbsp;
120
- <a href="#M000025">ip_based_schemes</a>&nbsp;&nbsp;
121
- <a href="#M000043">join</a>&nbsp;&nbsp;
122
- <a href="#M000006">join</a>&nbsp;&nbsp;
123
- <a href="#M000045">join!</a>&nbsp;&nbsp;
124
- <a href="#M000042">merge</a>&nbsp;&nbsp;
125
- <a href="#M000044">merge!</a>&nbsp;&nbsp;
126
- <a href="#M000012">new</a>&nbsp;&nbsp;
127
- <a href="#M000048">normalize</a>&nbsp;&nbsp;
128
- <a href="#M000049">normalize!</a>&nbsp;&nbsp;
129
- <a href="#M000010">normalized_encode</a>&nbsp;&nbsp;
130
- <a href="#M000001">parse</a>&nbsp;&nbsp;
131
- <a href="#M000017">password</a>&nbsp;&nbsp;
132
- <a href="#M000018">password=</a>&nbsp;&nbsp;
133
- <a href="#M000030">path</a>&nbsp;&nbsp;
134
- <a href="#M000031">path=</a>&nbsp;&nbsp;
135
- <a href="#M000027">port</a>&nbsp;&nbsp;
136
- <a href="#M000028">port=</a>&nbsp;&nbsp;
137
- <a href="#M000034">query</a>&nbsp;&nbsp;
138
- <a href="#M000035">query=</a>&nbsp;&nbsp;
139
- <a href="#M000039">relative?</a>&nbsp;&nbsp;
140
- <a href="#M000046">route_from</a>&nbsp;&nbsp;
141
- <a href="#M000047">route_to</a>&nbsp;&nbsp;
142
- <a href="#M000013">scheme</a>&nbsp;&nbsp;
143
- <a href="#M000014">scheme=</a>&nbsp;&nbsp;
144
- <a href="#M000026">scheme_mapping</a>&nbsp;&nbsp;
145
- <a href="#M000029">specified_port</a>&nbsp;&nbsp;
146
- <a href="#M000056">to_hash</a>&nbsp;&nbsp;
147
- <a href="#M000055">to_s</a>&nbsp;&nbsp;
148
- <a href="#M000008">unencode_segment</a>&nbsp;&nbsp;
149
- <a href="#M000015">user</a>&nbsp;&nbsp;
150
- <a href="#M000016">user=</a>&nbsp;&nbsp;
151
- <a href="#M000019">userinfo</a>&nbsp;&nbsp;
152
- <a href="#M000020">userinfo=</a>&nbsp;&nbsp;
153
- </div>
154
- </div>
155
-
156
- </div>
157
-
158
-
159
- <!-- if includes -->
160
-
161
- <div id="section">
162
-
163
- <div id="class-list">
164
- <h3 class="section-bar">Classes and Modules</h3>
165
-
166
- Module <a href="URI/CharacterClasses.html" class="link">Addressable::URI::CharacterClasses</a><br />
167
- Module <a href="URI/IDNA.html" class="link">Addressable::URI::IDNA</a><br />
168
- Class <a href="URI/InvalidOptionError.html" class="link">Addressable::URI::InvalidOptionError</a><br />
169
- Class <a href="URI/InvalidTemplateValue.html" class="link">Addressable::URI::InvalidTemplateValue</a><br />
170
- Class <a href="URI/InvalidURIError.html" class="link">Addressable::URI::InvalidURIError</a><br />
171
-
172
- </div>
173
-
174
-
175
- <div id="aliases-list">
176
- <h3 class="section-bar">External Aliases</h3>
177
-
178
- <div class="name-list">
179
- <table summary="aliases">
180
- <tr class="top-aligned-row context-row">
181
- <td class="context-item-name">encode</td>
182
- <td>-&gt;</td>
183
- <td class="context-item-value">escape</td>
184
- </tr>
185
- </table>
186
- </div>
187
- </div>
188
-
189
-
190
-
191
-
192
-
193
- <!-- if method_list -->
194
- <div id="methods">
195
- <h3 class="section-bar">Public Class methods</h3>
196
-
197
- <div id="method-M000003" class="method-detail">
198
- <a name="M000003"></a>
199
-
200
- <div class="method-heading">
201
- <a href="#M000003" class="method-signature">
202
- <span class="method-name">convert_path</span><span class="method-args">(path)</span>
203
- </a>
204
- </div>
205
-
206
- <div class="method-description">
207
- <p>
208
- Converts a <a href="URI.html#M000030">path</a> to a file protocol <a
209
- href="URI.html">URI</a>. If the <a href="URI.html#M000030">path</a>
210
- supplied is relative, it will be returned as a relative <a
211
- href="URI.html">URI</a>. If the <a href="URI.html#M000030">path</a>
212
- supplied is actually a <a href="URI.html">URI</a>, it will return the
213
- parsed <a href="URI.html">URI</a>.
214
- </p>
215
- <p><a class="source-toggle" href="#"
216
- onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
217
- <div class="method-source-code" id="M000003-source">
218
- <pre>
219
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 144</span>
220
- 144: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">convert_path</span>(<span class="ruby-identifier">path</span>)
221
- 145: <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">path</span>.<span class="ruby-identifier">nil?</span>
222
- 146:
223
- 147: <span class="ruby-identifier">converted_uri</span> = <span class="ruby-identifier">path</span>.<span class="ruby-identifier">strip</span>
224
- 148: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">converted_uri</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">converted_uri</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;/&quot;</span>
225
- 149: <span class="ruby-identifier">converted_uri</span> = <span class="ruby-value str">&quot;file://&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">converted_uri</span>
226
- 150: <span class="ruby-keyword kw">end</span>
227
- 151: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">converted_uri</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">&amp;&amp;</span>
228
- 152: <span class="ruby-identifier">converted_uri</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/^[a-zA-Z]:[\\\/]/</span>).<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
229
- 153: <span class="ruby-identifier">converted_uri</span> = <span class="ruby-value str">&quot;file:///&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">converted_uri</span>
230
- 154: <span class="ruby-keyword kw">end</span>
231
- 155: <span class="ruby-identifier">converted_uri</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^file:\/*/i</span>, <span class="ruby-value str">&quot;file:///&quot;</span>)
232
- 156: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">converted_uri</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^file:/i</span>
233
- 157: <span class="ruby-comment cmt"># Adjust windows-style uris</span>
234
- 158: <span class="ruby-identifier">converted_uri</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^file:\/\/\/([a-zA-Z])\|/i</span>, <span class="ruby-value str">'file:///\1:'</span>)
235
- 159: <span class="ruby-identifier">converted_uri</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/\\/</span>, <span class="ruby-value str">'/'</span>)
236
- 160: <span class="ruby-identifier">converted_uri</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">converted_uri</span>).<span class="ruby-identifier">normalize</span>
237
- 161: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">converted_uri</span>.<span class="ruby-identifier">path</span>) <span class="ruby-operator">&amp;&amp;</span>
238
- 162: <span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-identifier">converted_uri</span>.<span class="ruby-identifier">path</span>).<span class="ruby-identifier">directory?</span>
239
- 163: <span class="ruby-identifier">converted_uri</span>.<span class="ruby-identifier">path</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/\/$/</span>, <span class="ruby-value str">&quot;&quot;</span>)
240
- 164: <span class="ruby-identifier">converted_uri</span>.<span class="ruby-identifier">path</span> = <span class="ruby-identifier">converted_uri</span>.<span class="ruby-identifier">path</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'/'</span>
241
- 165: <span class="ruby-keyword kw">end</span>
242
- 166: <span class="ruby-keyword kw">else</span>
243
- 167: <span class="ruby-identifier">converted_uri</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">converted_uri</span>)
244
- 168: <span class="ruby-keyword kw">end</span>
245
- 169:
246
- 170: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">converted_uri</span>
247
- 171: <span class="ruby-keyword kw">end</span>
248
- </pre>
249
- </div>
250
- </div>
251
- </div>
252
-
253
- <div id="method-M000009" class="method-detail">
254
- <a name="M000009"></a>
255
-
256
- <div class="method-heading">
257
- <a href="#M000009" class="method-signature">
258
- <span class="method-name">encode</span><span class="method-args">(uri)</span>
259
- </a>
260
- </div>
261
-
262
- <div class="method-description">
263
- <p>
264
- Percent encodes any special characters in the <a href="URI.html">URI</a>.
265
- This method does not take IRIs or IDNs into account.
266
- </p>
267
- <p><a class="source-toggle" href="#"
268
- onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
269
- <div class="method-source-code" id="M000009-source">
270
- <pre>
271
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 373</span>
272
- 373: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode</span>(<span class="ruby-identifier">uri</span>)
273
- 374: <span class="ruby-identifier">uri_object</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">uri</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">to_s</span>)
274
- 375: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span>.<span class="ruby-identifier">new</span>(
275
- 376: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">scheme</span>,
276
- 377: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">SCHEME</span>),
277
- 378: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">user</span>,
278
- 379: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">AUTHORITY</span>),
279
- 380: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">password</span>,
280
- 381: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">AUTHORITY</span>),
281
- 382: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">host</span>,
282
- 383: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">AUTHORITY</span>),
283
- 384: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">specified_port</span>,
284
- 385: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">AUTHORITY</span>),
285
- 386: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">path</span>,
286
- 387: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">PATH</span>),
287
- 388: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">query</span>,
288
- 389: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">QUERY</span>),
289
- 390: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">fragment</span>,
290
- 391: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">FRAGMENT</span>)
291
- 392: ).<span class="ruby-identifier">to_s</span>
292
- 393: <span class="ruby-keyword kw">end</span>
293
- </pre>
294
- </div>
295
- </div>
296
- </div>
297
-
298
- <div id="method-M000007" class="method-detail">
299
- <a name="M000007"></a>
300
-
301
- <div class="method-heading">
302
- <a href="#M000007" class="method-signature">
303
- <span class="method-name">encode_segment</span><span class="method-args">(segment, character_class= Addressable::URI::CharacterClasses::RESERVED + Addressable::URI::CharacterClasses::UNRESERVED)</span>
304
- </a>
305
- </div>
306
-
307
- <div class="method-description">
308
- <p>
309
- Percent encodes a <a href="URI.html">URI</a> segment. Returns a string.
310
- Takes an optional character class parameter, which should be specified as a
311
- string containing a regular expression character class (not including the
312
- surrounding square brackets). The character class parameter defaults to the
313
- reserved plus unreserved character classes specified in RFC 3986. Usage of
314
- the constants within the <a
315
- href="URI/CharacterClasses.html">CharacterClasses</a> module is highly
316
- recommended when using this method.
317
- </p>
318
- <p>
319
- An example:
320
- </p>
321
- <pre>
322
- Addressable::URI.escape_segment(&quot;simple-example&quot;, &quot;b-zB-Z0-9&quot;)
323
- =&gt; &quot;simple%2Dex%61mple&quot;
324
- </pre>
325
- <p><a class="source-toggle" href="#"
326
- onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
327
- <div class="method-source-code" id="M000007-source">
328
- <pre>
329
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 351</span>
330
- 351: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">segment</span>, <span class="ruby-identifier">character_class</span>=
331
- 352: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">RESERVED</span> <span class="ruby-operator">+</span>
332
- 353: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">UNRESERVED</span>)
333
- 354: <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">segment</span>.<span class="ruby-identifier">nil?</span>
334
- 355: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">segment</span>.<span class="ruby-identifier">gsub</span>(
335
- 356: <span class="ruby-node">/[^#{character_class}]/</span>
336
- 357: ) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">sequence</span><span class="ruby-operator">|</span>
337
- 358: (<span class="ruby-value str">&quot;%&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">sequence</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-value str">'C'</span>)[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_s</span>(<span class="ruby-value">16</span>).<span class="ruby-identifier">upcase</span>)
338
- 359: <span class="ruby-keyword kw">end</span>
339
- 360: <span class="ruby-keyword kw">end</span>
340
- </pre>
341
- </div>
342
- </div>
343
- </div>
344
-
345
- <div id="method-M000004" class="method-detail">
346
- <a name="M000004"></a>
347
-
348
- <div class="method-heading">
349
- <a href="#M000004" class="method-signature">
350
- <span class="method-name">expand_template</span><span class="method-args">(pattern, mapping, processor=nil)</span>
351
- </a>
352
- </div>
353
-
354
- <div class="method-description">
355
- <p>
356
- Expands a <a href="URI.html">URI</a> template into a full <a
357
- href="URI.html">URI</a>.
358
- </p>
359
- <p>
360
- An optional processor object may be supplied. The object should respond to
361
- either the :validate or :transform messages or both. Both the :validate and
362
- :transform methods should take two parameters: :name and :value. The
363
- :validate method should return true or false; true if the value of the
364
- variable is valid, false otherwise. The :transform method should return the
365
- transformed variable value as a string.
366
- </p>
367
- <p>
368
- An example:
369
- </p>
370
- <pre>
371
- class ExampleProcessor
372
- def self.validate(name, value)
373
- return !!(value =~ /^[\w ]+$/) if name == &quot;query&quot;
374
- return true
375
- end
376
-
377
- def self.transform(name, value)
378
- return value.gsub(/ /, &quot;+&quot;) if name == &quot;query&quot;
379
- return value
380
- end
381
- end
382
-
383
- Addressable::URI.expand_template(
384
- &quot;http://example.com/search/{query}/&quot;,
385
- {&quot;query&quot; =&gt; &quot;an example search query&quot;},
386
- ExampleProcessor).to_s
387
- =&gt; &quot;http://example.com/search/an+example+search+query/&quot;
388
- </pre>
389
- <p><a class="source-toggle" href="#"
390
- onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
391
- <div class="method-source-code" id="M000004-source">
392
- <pre>
393
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 202</span>
394
- 202: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">expand_template</span>(<span class="ruby-identifier">pattern</span>, <span class="ruby-identifier">mapping</span>, <span class="ruby-identifier">processor</span>=<span class="ruby-keyword kw">nil</span>)
395
- 203: <span class="ruby-identifier">result</span> = <span class="ruby-identifier">pattern</span>.<span class="ruby-identifier">dup</span>
396
- 204: <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span> <span class="ruby-keyword kw">in</span> <span class="ruby-identifier">mapping</span>
397
- 205: <span class="ruby-identifier">transformed_value</span> = <span class="ruby-identifier">value</span>
398
- 206: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">processor</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
399
- 207: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">processor</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:validate</span>)
400
- 208: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">processor</span>.<span class="ruby-identifier">validate</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>)
401
- 209: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidTemplateValue</span>,
402
- 210: <span class="ruby-node">&quot;(#{name}, #{value}) is an invalid template value.&quot;</span>
403
- 211: <span class="ruby-keyword kw">end</span>
404
- 212: <span class="ruby-keyword kw">end</span>
405
- 213: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">processor</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:transform</span>)
406
- 214: <span class="ruby-identifier">transformed_value</span> = <span class="ruby-identifier">processor</span>.<span class="ruby-identifier">transform</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>)
407
- 215: <span class="ruby-keyword kw">end</span>
408
- 216: <span class="ruby-keyword kw">end</span>
409
- 217:
410
- 218: <span class="ruby-comment cmt"># Handle percent escaping</span>
411
- 219: <span class="ruby-identifier">transformed_value</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">transformed_value</span>,
412
- 220: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">RESERVED</span> <span class="ruby-operator">+</span>
413
- 221: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">UNRESERVED</span>)
414
- 222:
415
- 223: <span class="ruby-identifier">result</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-node">/\{#{Regexp.escape(name)}\}/</span>, <span class="ruby-identifier">transformed_value</span>)
416
- 224: <span class="ruby-keyword kw">end</span>
417
- 225: <span class="ruby-identifier">result</span>.<span class="ruby-identifier">gsub!</span>(
418
- 226: <span class="ruby-node">/\{[#{Addressable::URI::CharacterClasses::UNRESERVED}]+\}/</span>, <span class="ruby-value str">&quot;&quot;</span>)
419
- 227: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">result</span>)
420
- 228: <span class="ruby-keyword kw">end</span>
421
- </pre>
422
- </div>
423
- </div>
424
- </div>
425
-
426
- <div id="method-M000011" class="method-detail">
427
- <a name="M000011"></a>
428
-
429
- <div class="method-heading">
430
- <a href="#M000011" class="method-signature">
431
- <span class="method-name">extract</span><span class="method-args">(text, options={})</span>
432
- </a>
433
- </div>
434
-
435
- <div class="method-description">
436
- <p>
437
- Extracts uris from an arbitrary body of text.
438
- </p>
439
- <p><a class="source-toggle" href="#"
440
- onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
441
- <div class="method-source-code" id="M000011-source">
442
- <pre>
443
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 439</span>
444
- 439: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">extract</span>(<span class="ruby-identifier">text</span>, <span class="ruby-identifier">options</span>={})
445
- 440: <span class="ruby-identifier">defaults</span> = {<span class="ruby-identifier">:base</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">:parse</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>}
446
- 441: <span class="ruby-identifier">options</span> = <span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
447
- 442: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidOptionError</span> <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">options</span>.<span class="ruby-identifier">keys</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">keys</span>).<span class="ruby-identifier">empty?</span>
448
- 443: <span class="ruby-comment cmt"># This regular expression needs to be less forgiving or else it would</span>
449
- 444: <span class="ruby-comment cmt"># match virtually all text. Which isn't exactly what we're going for.</span>
450
- 445: <span class="ruby-identifier">extract_regex</span> = <span class="ruby-regexp re">/((([a-z\+]+):)[^ \n\&lt;\&gt;\&quot;\\]+[\w\/])/</span>
451
- 446: <span class="ruby-identifier">extracted_uris</span> =
452
- 447: <span class="ruby-identifier">text</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-identifier">extract_regex</span>).<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span> <span class="ruby-identifier">match</span>[<span class="ruby-value">0</span>] }
453
- 448: <span class="ruby-identifier">sgml_extract_regex</span> = <span class="ruby-regexp re">/&lt;[^&gt;]+href=\&quot;([^\&quot;]+?)\&quot;[^&gt;]*&gt;/</span>
454
- 449: <span class="ruby-identifier">sgml_extracted_uris</span> =
455
- 450: <span class="ruby-identifier">text</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-identifier">sgml_extract_regex</span>).<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span> <span class="ruby-identifier">match</span>[<span class="ruby-value">0</span>] }
456
- 451: <span class="ruby-identifier">extracted_uris</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">sgml_extracted_uris</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">extracted_uris</span>)
457
- 452: <span class="ruby-identifier">textile_extract_regex</span> = <span class="ruby-regexp re">/\&quot;.+?\&quot;:([^ ]+\/[^ ]+)[ \,\.\;\:\?\!\&lt;\&gt;\&quot;]/i</span>
458
- 453: <span class="ruby-identifier">textile_extracted_uris</span> =
459
- 454: <span class="ruby-identifier">text</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-identifier">textile_extract_regex</span>).<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span> <span class="ruby-identifier">match</span>[<span class="ruby-value">0</span>] }
460
- 455: <span class="ruby-identifier">extracted_uris</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">textile_extracted_uris</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">extracted_uris</span>)
461
- 456: <span class="ruby-identifier">parsed_uris</span> = []
462
- 457: <span class="ruby-identifier">base_uri</span> = <span class="ruby-keyword kw">nil</span>
463
- 458: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:base</span>] <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
464
- 459: <span class="ruby-identifier">base_uri</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:base</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:base</span>].<span class="ruby-identifier">kind_of?</span>(<span class="ruby-keyword kw">self</span>)
465
- 460: <span class="ruby-identifier">base_uri</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:base</span>].<span class="ruby-identifier">to_s</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">base_uri</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span>
466
- 461: <span class="ruby-keyword kw">end</span>
467
- 462: <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">uri_string</span> <span class="ruby-keyword kw">in</span> <span class="ruby-identifier">extracted_uris</span>
468
- 463: <span class="ruby-keyword kw">begin</span>
469
- 464: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">base_uri</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span>
470
- 465: <span class="ruby-identifier">parsed_uris</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">uri_string</span>)
471
- 466: <span class="ruby-keyword kw">else</span>
472
- 467: <span class="ruby-identifier">parsed_uris</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-identifier">base_uri</span> <span class="ruby-operator">+</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">uri_string</span>))
473
- 468: <span class="ruby-keyword kw">end</span>
474
- 469: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span>
475
- 470: <span class="ruby-keyword kw">nil</span>
476
- 471: <span class="ruby-keyword kw">end</span>
477
- 472: <span class="ruby-keyword kw">end</span>
478
- 473: <span class="ruby-identifier">parsed_uris</span>.<span class="ruby-identifier">reject!</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">uri</span><span class="ruby-operator">|</span>
479
- 474: (<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/T\d+/</span> <span class="ruby-operator">||</span>
480
- 475: <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;xmlns&quot;</span> <span class="ruby-operator">||</span>
481
- 476: <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;xml&quot;</span> <span class="ruby-operator">||</span>
482
- 477: <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;thr&quot;</span> <span class="ruby-operator">||</span>
483
- 478: <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;this&quot;</span> <span class="ruby-operator">||</span>
484
- 479: <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;float&quot;</span> <span class="ruby-operator">||</span>
485
- 480: <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;user&quot;</span> <span class="ruby-operator">||</span>
486
- 481: <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;username&quot;</span> <span class="ruby-operator">||</span>
487
- 482: <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;out&quot;</span>)
488
- 483: <span class="ruby-keyword kw">end</span>
489
- 484: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:parse</span>]
490
- 485: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">parsed_uris</span>
491
- 486: <span class="ruby-keyword kw">else</span>
492
- 487: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">parsed_uris</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">uri</span><span class="ruby-operator">|</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">to_s</span> }
493
- 488: <span class="ruby-keyword kw">end</span>
494
- 489: <span class="ruby-keyword kw">end</span>
495
- </pre>
496
- </div>
497
- </div>
498
- </div>
499
-
500
- <div id="method-M000002" class="method-detail">
501
- <a name="M000002"></a>
502
-
503
- <div class="method-heading">
504
- <a href="#M000002" class="method-signature">
505
- <span class="method-name">heuristic_parse</span><span class="method-args">(input, hints={})</span>
506
- </a>
507
- </div>
508
-
509
- <div class="method-description">
510
- <p>
511
- Converts an input to a <a href="URI.html">URI</a>. The input does not have
512
- to be a valid <a href="URI.html">URI</a> &#8212; the method will use
513
- heuristics to guess what <a href="URI.html">URI</a> was intended. This is
514
- not standards compliant, merely <a
515
- href="URI.html#M000015">user</a>-friendly.
516
- </p>
517
- <p><a class="source-toggle" href="#"
518
- onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
519
- <div class="method-source-code" id="M000002-source">
520
- <pre>
521
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 107</span>
522
- 107: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">heuristic_parse</span>(<span class="ruby-identifier">input</span>, <span class="ruby-identifier">hints</span>={})
523
- 108: <span class="ruby-identifier">input</span> = <span class="ruby-identifier">input</span>.<span class="ruby-identifier">dup</span>
524
- 109: <span class="ruby-identifier">hints</span> = {
525
- 110: <span class="ruby-identifier">:scheme</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;http&quot;</span>
526
- 111: }.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">hints</span>)
527
- 112: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">input</span>
528
- 113: <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/^http:\/+/</span>
529
- 114: <span class="ruby-identifier">input</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^http:\/+/</span>, <span class="ruby-value str">&quot;http://&quot;</span>)
530
- 115: <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/^feed:\/+http:\/+/</span>
531
- 116: <span class="ruby-identifier">input</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^feed:\/+http:\/+/</span>, <span class="ruby-value str">&quot;feed:http://&quot;</span>)
532
- 117: <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/^feed:\/+/</span>
533
- 118: <span class="ruby-identifier">input</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^feed:\/+/</span>, <span class="ruby-value str">&quot;feed://&quot;</span>)
534
- 119: <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/^file:\/+/</span>
535
- 120: <span class="ruby-identifier">input</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/^file:\/+/</span>, <span class="ruby-value str">&quot;file:///&quot;</span>)
536
- 121: <span class="ruby-keyword kw">end</span>
537
- 122: <span class="ruby-identifier">parsed</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">input</span>)
538
- 123: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">parsed</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^[^\/?#\.]+\.[^\/?#]+$/</span>
539
- 124: <span class="ruby-identifier">parsed</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">hints</span>[<span class="ruby-identifier">:scheme</span>] <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;://&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">input</span>)
540
- 125: <span class="ruby-keyword kw">end</span>
541
- 126: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">parsed</span>.<span class="ruby-identifier">authority</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span>
542
- 127: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">parsed</span>.<span class="ruby-identifier">path</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^[^\/]+\./</span>
543
- 128: <span class="ruby-identifier">new_host</span> = <span class="ruby-identifier">parsed</span>.<span class="ruby-identifier">path</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/^([^\/]+\.[^\/]*)/</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]
544
- 129: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_host</span>
545
- 130: <span class="ruby-identifier">new_path</span> = <span class="ruby-identifier">parsed</span>.<span class="ruby-identifier">path</span>.<span class="ruby-identifier">gsub</span>(
546
- 131: <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;^&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">new_host</span>)), <span class="ruby-value str">&quot;&quot;</span>)
547
- 132: <span class="ruby-identifier">parsed</span>.<span class="ruby-identifier">host</span> = <span class="ruby-identifier">new_host</span>
548
- 133: <span class="ruby-identifier">parsed</span>.<span class="ruby-identifier">path</span> = <span class="ruby-identifier">new_path</span>
549
- 134: <span class="ruby-identifier">parsed</span>.<span class="ruby-identifier">scheme</span> = <span class="ruby-identifier">hints</span>[<span class="ruby-identifier">:scheme</span>]
550
- 135: <span class="ruby-keyword kw">end</span>
551
- 136: <span class="ruby-keyword kw">end</span>
552
- 137: <span class="ruby-keyword kw">end</span>
553
- 138: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">parsed</span>
554
- 139: <span class="ruby-keyword kw">end</span>
555
- </pre>
556
- </div>
557
- </div>
558
- </div>
559
-
560
- <div id="method-M000025" class="method-detail">
561
- <a name="M000025"></a>
562
-
563
- <div class="method-heading">
564
- <a href="#M000025" class="method-signature">
565
- <span class="method-name">ip_based_schemes</span><span class="method-args">()</span>
566
- </a>
567
- </div>
568
-
569
- <div class="method-description">
570
- <p>
571
- Returns an array of known ip-based schemes. These schemes typically use a
572
- similar <a href="URI.html">URI</a> form: //&lt;<a
573
- href="URI.html#M000015">user</a>&gt;:&lt;<a
574
- href="URI.html#M000017">password</a>&gt;@&lt;<a
575
- href="URI.html#M000021">host</a>&gt;:&lt;<a
576
- href="URI.html#M000027">port</a>&gt;/&lt;url-<a
577
- href="URI.html#M000030">path</a>&gt;
578
- </p>
579
- <p><a class="source-toggle" href="#"
580
- onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
581
- <div class="method-source-code" id="M000025-source">
582
- <pre>
583
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 662</span>
584
- 662: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">ip_based_schemes</span>
585
- 663: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme_mapping</span>.<span class="ruby-identifier">keys</span>
586
- 664: <span class="ruby-keyword kw">end</span>
587
- </pre>
588
- </div>
589
- </div>
590
- </div>
591
-
592
- <div id="method-M000006" class="method-detail">
593
- <a name="M000006"></a>
594
-
595
- <div class="method-heading">
596
- <a href="#M000006" class="method-signature">
597
- <span class="method-name">join</span><span class="method-args">(*uris)</span>
598
- </a>
599
- </div>
600
-
601
- <div class="method-description">
602
- <p>
603
- Joins several uris together.
604
- </p>
605
- <p><a class="source-toggle" href="#"
606
- onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
607
- <div class="method-source-code" id="M000006-source">
608
- <pre>
609
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 328</span>
610
- 328: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">join</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">uris</span>)
611
- 329: <span class="ruby-identifier">uri_objects</span> = <span class="ruby-identifier">uris</span>.<span class="ruby-identifier">collect</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">uri</span><span class="ruby-operator">|</span>
612
- 330: <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">uri</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">to_s</span>)
613
- 331: <span class="ruby-keyword kw">end</span>
614
- 332: <span class="ruby-identifier">result</span> = <span class="ruby-identifier">uri_objects</span>.<span class="ruby-identifier">shift</span>.<span class="ruby-identifier">dup</span>
615
- 333: <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">uri</span> <span class="ruby-keyword kw">in</span> <span class="ruby-identifier">uri_objects</span>
616
- 334: <span class="ruby-identifier">result</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">uri</span>)
617
- 335: <span class="ruby-keyword kw">end</span>
618
- 336: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">result</span>
619
- 337: <span class="ruby-keyword kw">end</span>
620
- </pre>
621
- </div>
622
- </div>
623
- </div>
624
-
625
- <div id="method-M000012" class="method-detail">
626
- <a name="M000012"></a>
627
-
628
- <div class="method-heading">
629
- <a href="#M000012" class="method-signature">
630
- <span class="method-name">new</span><span class="method-args">(scheme, user, password, host, port, path, query, fragment)</span>
631
- </a>
632
- </div>
633
-
634
- <div class="method-description">
635
- <p>
636
- Creates a <a href="URI.html#M000012">new</a> uri object from component
637
- parts. Passing nil for any of these parameters is acceptable.
638
- </p>
639
- <p><a class="source-toggle" href="#"
640
- onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
641
- <div class="method-source-code" id="M000012-source">
642
- <pre>
643
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 493</span>
644
- 493: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">scheme</span>, <span class="ruby-identifier">user</span>, <span class="ruby-identifier">password</span>, <span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">query</span>, <span class="ruby-identifier">fragment</span>)
645
- 494: <span class="ruby-ivar">@scheme</span> = <span class="ruby-identifier">scheme</span>
646
- 495: <span class="ruby-ivar">@scheme</span> = <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@scheme</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">strip</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span>
647
- 496: <span class="ruby-ivar">@user</span> = <span class="ruby-identifier">user</span>
648
- 497: <span class="ruby-ivar">@password</span> = <span class="ruby-identifier">password</span>
649
- 498: <span class="ruby-ivar">@host</span> = <span class="ruby-identifier">host</span>
650
- 499: <span class="ruby-ivar">@specified_port</span> = <span class="ruby-identifier">port</span>.<span class="ruby-identifier">to_s</span>
651
- 500: <span class="ruby-ivar">@port</span> = <span class="ruby-identifier">port</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Fixnum</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">port</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">port</span>
652
- 501: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@port</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span>(<span class="ruby-ivar">@port</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\d+$/</span>)
653
- 502: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidURIError</span>,
654
- 503: <span class="ruby-node">&quot;Invalid port number: #{@port.inspect}&quot;</span>
655
- 504: <span class="ruby-keyword kw">end</span>
656
- 505: <span class="ruby-ivar">@port</span> = <span class="ruby-ivar">@port</span>.<span class="ruby-identifier">to_i</span>
657
- 506: <span class="ruby-ivar">@port</span> = <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@port</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
658
- 507: <span class="ruby-ivar">@path</span> = (<span class="ruby-identifier">path</span> <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;&quot;</span>)
659
- 508: <span class="ruby-ivar">@query</span> = <span class="ruby-identifier">query</span>
660
- 509: <span class="ruby-ivar">@fragment</span> = <span class="ruby-identifier">fragment</span>
661
- 510:
662
- 511: <span class="ruby-identifier">validate</span>()
663
- 512: <span class="ruby-keyword kw">end</span>
664
- </pre>
665
- </div>
666
- </div>
667
- </div>
668
-
669
- <div id="method-M000010" class="method-detail">
670
- <a name="M000010"></a>
671
-
672
- <div class="method-heading">
673
- <a href="#M000010" class="method-signature">
674
- <span class="method-name">normalized_encode</span><span class="method-args">(uri)</span>
675
- </a>
676
- </div>
677
-
678
- <div class="method-description">
679
- <p>
680
- Normalizes the encoding of a <a href="URI.html">URI</a>. Characters within
681
- a hostname are not percent encoded to allow for internationalized domain
682
- names.
683
- </p>
684
- <p><a class="source-toggle" href="#"
685
- onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
686
- <div class="method-source-code" id="M000010-source">
687
- <pre>
688
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 401</span>
689
- 401: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">normalized_encode</span>(<span class="ruby-identifier">uri</span>)
690
- 402: <span class="ruby-identifier">uri_object</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">uri</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">to_s</span>)
691
- 403: <span class="ruby-identifier">segments</span> = {
692
- 404: <span class="ruby-identifier">:scheme</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">unencode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">scheme</span>),
693
- 405: <span class="ruby-identifier">:user</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">unencode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">user</span>),
694
- 406: <span class="ruby-identifier">:password</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">unencode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">password</span>),
695
- 407: <span class="ruby-identifier">:host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">unencode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">host</span>),
696
- 408: <span class="ruby-identifier">:port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">unencode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">specified_port</span>),
697
- 409: <span class="ruby-identifier">:path</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">unencode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">path</span>),
698
- 410: <span class="ruby-identifier">:query</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">unencode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">query</span>),
699
- 411: <span class="ruby-identifier">:fragment</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">unencode_segment</span>(<span class="ruby-identifier">uri_object</span>.<span class="ruby-identifier">fragment</span>)
700
- 412: }
701
- 413: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">IDNA</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:use_libidn?</span>)
702
- 414: <span class="ruby-identifier">segments</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
703
- 415: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
704
- 416: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-constant">IDN</span><span class="ruby-operator">::</span><span class="ruby-constant">Stringprep</span>.<span class="ruby-identifier">nfkc_normalize</span>(<span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>)
705
- 417: <span class="ruby-keyword kw">end</span>
706
- 418: <span class="ruby-keyword kw">end</span>
707
- 419: <span class="ruby-keyword kw">end</span>
708
- 420: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span>.<span class="ruby-identifier">new</span>(
709
- 421: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:scheme</span>],
710
- 422: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">SCHEME</span>),
711
- 423: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:user</span>],
712
- 424: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">AUTHORITY</span>),
713
- 425: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:password</span>],
714
- 426: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">AUTHORITY</span>),
715
- 427: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:host</span>],
716
- 428: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:port</span>],
717
- 429: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:path</span>],
718
- 430: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">PATH</span>),
719
- 431: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:query</span>],
720
- 432: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">QUERY</span>),
721
- 433: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encode_segment</span>(<span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:fragment</span>],
722
- 434: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">CharacterClasses</span><span class="ruby-operator">::</span><span class="ruby-constant">FRAGMENT</span>)
723
- 435: ).<span class="ruby-identifier">to_s</span>
724
- 436: <span class="ruby-keyword kw">end</span>
725
- </pre>
726
- </div>
727
- </div>
728
- </div>
729
-
730
- <div id="method-M000001" class="method-detail">
731
- <a name="M000001"></a>
732
-
733
- <div class="method-heading">
734
- <a href="#M000001" class="method-signature">
735
- <span class="method-name">parse</span><span class="method-args">(uri_string)</span>
736
- </a>
737
- </div>
738
-
739
- <div class="method-description">
740
- <p>
741
- Returns a <a href="URI.html">URI</a> object based on the parsed string.
742
- </p>
743
- <p><a class="source-toggle" href="#"
744
- onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
745
- <div class="method-source-code" id="M000001-source">
746
- <pre>
747
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 60</span>
748
- 60: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">uri_string</span>)
749
- 61: <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">uri_string</span>.<span class="ruby-identifier">nil?</span>
750
- 62:
751
- 63: <span class="ruby-comment cmt"># If a URI object is passed, just return itself.</span>
752
- 64: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">uri_string</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri_string</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-keyword kw">self</span>)
753
- 65:
754
- 66: <span class="ruby-comment cmt"># If a URI object of the Ruby standard library variety is passed,</span>
755
- 67: <span class="ruby-comment cmt"># convert it to a string, then parse the string.</span>
756
- 68: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri_string</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^URI::/</span>
757
- 69: <span class="ruby-identifier">uri_string</span> = <span class="ruby-identifier">uri_string</span>.<span class="ruby-identifier">to_s</span>
758
- 70: <span class="ruby-keyword kw">end</span>
759
- 71:
760
- 72: <span class="ruby-identifier">uri_regex</span> =
761
- 73: <span class="ruby-regexp re">/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/</span>
762
- 74: <span class="ruby-identifier">scan</span> = <span class="ruby-identifier">uri_string</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-identifier">uri_regex</span>)
763
- 75: <span class="ruby-identifier">fragments</span> = <span class="ruby-identifier">scan</span>[<span class="ruby-value">0</span>]
764
- 76: <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">fragments</span>.<span class="ruby-identifier">nil?</span>
765
- 77: <span class="ruby-identifier">scheme</span> = <span class="ruby-identifier">fragments</span>[<span class="ruby-value">1</span>]
766
- 78: <span class="ruby-identifier">authority</span> = <span class="ruby-identifier">fragments</span>[<span class="ruby-value">3</span>]
767
- 79: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">fragments</span>[<span class="ruby-value">4</span>]
768
- 80: <span class="ruby-identifier">query</span> = <span class="ruby-identifier">fragments</span>[<span class="ruby-value">6</span>]
769
- 81: <span class="ruby-identifier">fragment</span> = <span class="ruby-identifier">fragments</span>[<span class="ruby-value">8</span>]
770
- 82: <span class="ruby-identifier">userinfo</span> = <span class="ruby-keyword kw">nil</span>
771
- 83: <span class="ruby-identifier">user</span> = <span class="ruby-keyword kw">nil</span>
772
- 84: <span class="ruby-identifier">password</span> = <span class="ruby-keyword kw">nil</span>
773
- 85: <span class="ruby-identifier">host</span> = <span class="ruby-keyword kw">nil</span>
774
- 86: <span class="ruby-identifier">port</span> = <span class="ruby-keyword kw">nil</span>
775
- 87: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">authority</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
776
- 88: <span class="ruby-identifier">userinfo</span> = <span class="ruby-identifier">authority</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/^([^\[\]]*)@/</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]
777
- 89: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">userinfo</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
778
- 90: <span class="ruby-identifier">user</span> = <span class="ruby-identifier">userinfo</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/^([^:]*):?/</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]
779
- 91: <span class="ruby-identifier">password</span> = <span class="ruby-identifier">userinfo</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/:(.*)$/</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]
780
- 92: <span class="ruby-keyword kw">end</span>
781
- 93: <span class="ruby-identifier">host</span> = <span class="ruby-identifier">authority</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/^([^\[\]]*)@/</span>, <span class="ruby-value str">&quot;&quot;</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/:([^:@\[\]]*?)$/</span>, <span class="ruby-value str">&quot;&quot;</span>)
782
- 94: <span class="ruby-identifier">port</span> = <span class="ruby-identifier">authority</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/:([^:@\[\]]*?)$/</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]
783
- 95: <span class="ruby-keyword kw">end</span>
784
- 96: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">port</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">port</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span>
785
- 97: <span class="ruby-identifier">port</span> = <span class="ruby-keyword kw">nil</span>
786
- 98: <span class="ruby-keyword kw">end</span>
787
- 99:
788
- 100: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span>.<span class="ruby-identifier">new</span>(
789
- 101: <span class="ruby-identifier">scheme</span>, <span class="ruby-identifier">user</span>, <span class="ruby-identifier">password</span>, <span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">query</span>, <span class="ruby-identifier">fragment</span>)
790
- 102: <span class="ruby-keyword kw">end</span>
791
- </pre>
792
- </div>
793
- </div>
794
- </div>
795
-
796
- <div id="method-M000026" class="method-detail">
797
- <a name="M000026"></a>
798
-
799
- <div class="method-heading">
800
- <a href="#M000026" class="method-signature">
801
- <span class="method-name">scheme_mapping</span><span class="method-args">()</span>
802
- </a>
803
- </div>
804
-
805
- <div class="method-description">
806
- <p>
807
- Returns a hash of common IP-based schemes and their default <a
808
- href="URI.html#M000027">port</a> numbers. Adding <a
809
- href="URI.html#M000012">new</a> schemes to this hash, as necessary, will
810
- allow for better <a href="URI.html">URI</a> normalization.
811
- </p>
812
- <p><a class="source-toggle" href="#"
813
- onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
814
- <div class="method-source-code" id="M000026-source">
815
- <pre>
816
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 669</span>
817
- 669: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme_mapping</span>
818
- 670: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-keyword kw">defined?</span>(<span class="ruby-ivar">@protocol_mapping</span>) <span class="ruby-operator">||</span> <span class="ruby-ivar">@protocol_mapping</span>.<span class="ruby-identifier">nil?</span>
819
- 671: <span class="ruby-ivar">@protocol_mapping</span> = {
820
- 672: <span class="ruby-value str">&quot;http&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">80</span>,
821
- 673: <span class="ruby-value str">&quot;https&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">443</span>,
822
- 674: <span class="ruby-value str">&quot;ftp&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">21</span>,
823
- 675: <span class="ruby-value str">&quot;tftp&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">69</span>,
824
- 676: <span class="ruby-value str">&quot;ssh&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">22</span>,
825
- 677: <span class="ruby-value str">&quot;svn+ssh&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">22</span>,
826
- 678: <span class="ruby-value str">&quot;telnet&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">23</span>,
827
- 679: <span class="ruby-value str">&quot;nntp&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">119</span>,
828
- 680: <span class="ruby-value str">&quot;gopher&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">70</span>,
829
- 681: <span class="ruby-value str">&quot;wais&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">210</span>,
830
- 682: <span class="ruby-value str">&quot;ldap&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">389</span>,
831
- 683: <span class="ruby-value str">&quot;prospero&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">1525</span>
832
- 684: }
833
- 685: <span class="ruby-keyword kw">end</span>
834
- 686: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@protocol_mapping</span>
835
- 687: <span class="ruby-keyword kw">end</span>
836
- </pre>
837
- </div>
838
- </div>
839
- </div>
840
-
841
- <div id="method-M000008" class="method-detail">
842
- <a name="M000008"></a>
843
-
844
- <div class="method-heading">
845
- <a href="#M000008" class="method-signature">
846
- <span class="method-name">unencode_segment</span><span class="method-args">(segment)</span>
847
- </a>
848
- </div>
849
-
850
- <div class="method-description">
851
- <p>
852
- Unencodes any percent encoded characters within a <a
853
- href="URI.html">URI</a> segment. Returns a string.
854
- </p>
855
- <p><a class="source-toggle" href="#"
856
- onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
857
- <div class="method-source-code" id="M000008-source">
858
- <pre>
859
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 364</span>
860
- 364: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">unencode_segment</span>(<span class="ruby-identifier">segment</span>)
861
- 365: <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">segment</span>.<span class="ruby-identifier">nil?</span>
862
- 366: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">segment</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/%[0-9a-f]{2}/i</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">sequence</span><span class="ruby-operator">|</span>
863
- 367: <span class="ruby-identifier">sequence</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">3</span>].<span class="ruby-identifier">to_i</span>(<span class="ruby-value">16</span>).<span class="ruby-identifier">chr</span>
864
- 368: <span class="ruby-keyword kw">end</span>
865
- 369: <span class="ruby-keyword kw">end</span>
866
- </pre>
867
- </div>
868
- </div>
869
- </div>
870
-
871
- <h3 class="section-bar">Public Instance methods</h3>
872
-
873
- <div id="method-M000041" class="method-detail">
874
- <a name="M000041"></a>
875
-
876
- <div class="method-heading">
877
- <a href="#M000041" class="method-signature">
878
- <span class="method-name">+</span><span class="method-args">(uri)</span>
879
- </a>
880
- </div>
881
-
882
- <div class="method-description">
883
- <p>
884
- Joins two URIs together.
885
- </p>
886
- <p><a class="source-toggle" href="#"
887
- onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
888
- <div class="method-source-code" id="M000041-source">
889
- <pre>
890
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 788</span>
891
- 788: <span class="ruby-keyword kw">def</span> <span class="ruby-operator">+</span>(<span class="ruby-identifier">uri</span>)
892
- 789: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">uri</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>)
893
- 790: <span class="ruby-identifier">uri</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">to_s</span>)
894
- 791: <span class="ruby-keyword kw">end</span>
895
- 792: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span>
896
- 793: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">dup</span>
897
- 794: <span class="ruby-keyword kw">end</span>
898
- 795:
899
- 796: <span class="ruby-identifier">joined_scheme</span> = <span class="ruby-keyword kw">nil</span>
900
- 797: <span class="ruby-identifier">joined_user</span> = <span class="ruby-keyword kw">nil</span>
901
- 798: <span class="ruby-identifier">joined_password</span> = <span class="ruby-keyword kw">nil</span>
902
- 799: <span class="ruby-identifier">joined_host</span> = <span class="ruby-keyword kw">nil</span>
903
- 800: <span class="ruby-identifier">joined_port</span> = <span class="ruby-keyword kw">nil</span>
904
- 801: <span class="ruby-identifier">joined_path</span> = <span class="ruby-keyword kw">nil</span>
905
- 802: <span class="ruby-identifier">joined_query</span> = <span class="ruby-keyword kw">nil</span>
906
- 803: <span class="ruby-identifier">joined_fragment</span> = <span class="ruby-keyword kw">nil</span>
907
- 804:
908
- 805: <span class="ruby-comment cmt"># Section 5.2.2 of RFC 3986</span>
909
- 806: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
910
- 807: <span class="ruby-identifier">joined_scheme</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span>
911
- 808: <span class="ruby-identifier">joined_user</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">user</span>
912
- 809: <span class="ruby-identifier">joined_password</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">password</span>
913
- 810: <span class="ruby-identifier">joined_host</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">host</span>
914
- 811: <span class="ruby-identifier">joined_port</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">specified_port</span>
915
- 812: <span class="ruby-identifier">joined_path</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">normalize_path</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span>)
916
- 813: <span class="ruby-identifier">joined_query</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">query</span>
917
- 814: <span class="ruby-keyword kw">else</span>
918
- 815: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">authority</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
919
- 816: <span class="ruby-identifier">joined_user</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">user</span>
920
- 817: <span class="ruby-identifier">joined_password</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">password</span>
921
- 818: <span class="ruby-identifier">joined_host</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">host</span>
922
- 819: <span class="ruby-identifier">joined_port</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">specified_port</span>
923
- 820: <span class="ruby-identifier">joined_path</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">normalize_path</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span>)
924
- 821: <span class="ruby-identifier">joined_query</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">query</span>
925
- 822: <span class="ruby-keyword kw">else</span>
926
- 823: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span>
927
- 824: <span class="ruby-identifier">joined_path</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span>
928
- 825: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">query</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
929
- 826: <span class="ruby-identifier">joined_query</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">query</span>
930
- 827: <span class="ruby-keyword kw">else</span>
931
- 828: <span class="ruby-identifier">joined_query</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">query</span>
932
- 829: <span class="ruby-keyword kw">end</span>
933
- 830: <span class="ruby-keyword kw">else</span>
934
- 831: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;/&quot;</span>
935
- 832: <span class="ruby-identifier">joined_path</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">normalize_path</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span>)
936
- 833: <span class="ruby-keyword kw">else</span>
937
- 834: <span class="ruby-identifier">base_path</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span>.<span class="ruby-identifier">dup</span>
938
- 835: <span class="ruby-identifier">base_path</span> = <span class="ruby-value str">&quot;&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">base_path</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span>
939
- 836: <span class="ruby-identifier">base_path</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">normalize_path</span>(<span class="ruby-identifier">base_path</span>)
940
- 837:
941
- 838: <span class="ruby-comment cmt"># Section 5.2.3 of RFC 3986</span>
942
- 839: <span class="ruby-comment cmt">#</span>
943
- 840: <span class="ruby-comment cmt"># Removes the right-most path segment from the base path.</span>
944
- 841: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">base_path</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/\//</span>
945
- 842: <span class="ruby-identifier">base_path</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/\/[^\/]+$/</span>, <span class="ruby-value str">&quot;/&quot;</span>)
946
- 843: <span class="ruby-keyword kw">else</span>
947
- 844: <span class="ruby-identifier">base_path</span> = <span class="ruby-value str">&quot;&quot;</span>
948
- 845: <span class="ruby-keyword kw">end</span>
949
- 846:
950
- 847: <span class="ruby-comment cmt"># If the base path is empty and an authority segment has been</span>
951
- 848: <span class="ruby-comment cmt"># defined, use a base path of &quot;/&quot;</span>
952
- 849: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">base_path</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">authority</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
953
- 850: <span class="ruby-identifier">base_path</span> = <span class="ruby-value str">&quot;/&quot;</span>
954
- 851: <span class="ruby-keyword kw">end</span>
955
- 852:
956
- 853: <span class="ruby-identifier">joined_path</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">normalize_path</span>(<span class="ruby-identifier">base_path</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span>)
957
- 854: <span class="ruby-keyword kw">end</span>
958
- 855: <span class="ruby-identifier">joined_query</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">query</span>
959
- 856: <span class="ruby-keyword kw">end</span>
960
- 857: <span class="ruby-identifier">joined_user</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">user</span>
961
- 858: <span class="ruby-identifier">joined_password</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">password</span>
962
- 859: <span class="ruby-identifier">joined_host</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">host</span>
963
- 860: <span class="ruby-identifier">joined_port</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">specified_port</span>
964
- 861: <span class="ruby-keyword kw">end</span>
965
- 862: <span class="ruby-identifier">joined_scheme</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme</span>
966
- 863: <span class="ruby-keyword kw">end</span>
967
- 864: <span class="ruby-identifier">joined_fragment</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">fragment</span>
968
- 865:
969
- 866: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span>.<span class="ruby-identifier">new</span>(
970
- 867: <span class="ruby-identifier">joined_scheme</span>,
971
- 868: <span class="ruby-identifier">joined_user</span>,
972
- 869: <span class="ruby-identifier">joined_password</span>,
973
- 870: <span class="ruby-identifier">joined_host</span>,
974
- 871: <span class="ruby-identifier">joined_port</span>,
975
- 872: <span class="ruby-identifier">joined_path</span>,
976
- 873: <span class="ruby-identifier">joined_query</span>,
977
- 874: <span class="ruby-identifier">joined_fragment</span>
978
- 875: )
979
- 876: <span class="ruby-keyword kw">end</span>
980
- </pre>
981
- </div>
982
- </div>
983
- </div>
984
-
985
- <div id="method-M000052" class="method-detail">
986
- <a name="M000052"></a>
987
-
988
- <div class="method-heading">
989
- <a href="#M000052" class="method-signature">
990
- <span class="method-name">==</span><span class="method-args">(uri)</span>
991
- </a>
992
- </div>
993
-
994
- <div class="method-description">
995
- <p>
996
- Returns true if the <a href="URI.html">URI</a> objects are equal. This
997
- method normalizes both URIs before doing the comparison.
998
- </p>
999
- <p><a class="source-toggle" href="#"
1000
- onclick="toggleCode('M000052-source');return false;">[Source]</a></p>
1001
- <div class="method-source-code" id="M000052-source">
1002
- <pre>
1003
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1062</span>
1004
- 1062: <span class="ruby-keyword kw">def</span> <span class="ruby-operator">==</span>(<span class="ruby-identifier">uri</span>)
1005
- 1063: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>)
1006
- 1064: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">normalize</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">normalize</span>.<span class="ruby-identifier">to_s</span>
1007
- 1065: <span class="ruby-keyword kw">end</span>
1008
- </pre>
1009
- </div>
1010
- </div>
1011
- </div>
1012
-
1013
- <div id="method-M000051" class="method-detail">
1014
- <a name="M000051"></a>
1015
-
1016
- <div class="method-heading">
1017
- <a href="#M000051" class="method-signature">
1018
- <span class="method-name">===</span><span class="method-args">(uri)</span>
1019
- </a>
1020
- </div>
1021
-
1022
- <div class="method-description">
1023
- <p>
1024
- Returns true if the <a href="URI.html">URI</a> objects are equal. This
1025
- method normalizes both URIs before doing the comparison, and allows
1026
- comparison against strings.
1027
- </p>
1028
- <p><a class="source-toggle" href="#"
1029
- onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
1030
- <div class="method-source-code" id="M000051-source">
1031
- <pre>
1032
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1047</span>
1033
- 1047: <span class="ruby-keyword kw">def</span> <span class="ruby-operator">===</span>(<span class="ruby-identifier">uri</span>)
1034
- 1048: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:normalize</span>)
1035
- 1049: <span class="ruby-identifier">uri_string</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">normalize</span>.<span class="ruby-identifier">to_s</span>
1036
- 1050: <span class="ruby-keyword kw">else</span>
1037
- 1051: <span class="ruby-keyword kw">begin</span>
1038
- 1052: <span class="ruby-identifier">uri_string</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">to_s</span>).<span class="ruby-identifier">normalize</span>.<span class="ruby-identifier">to_s</span>
1039
- 1053: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">InvalidURIError</span>
1040
- 1054: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
1041
- 1055: <span class="ruby-keyword kw">end</span>
1042
- 1056: <span class="ruby-keyword kw">end</span>
1043
- 1057: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">normalize</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">uri_string</span>
1044
- 1058: <span class="ruby-keyword kw">end</span>
1045
- </pre>
1046
- </div>
1047
- </div>
1048
- </div>
1049
-
1050
- <div id="method-M000040" class="method-detail">
1051
- <a name="M000040"></a>
1052
-
1053
- <div class="method-heading">
1054
- <a href="#M000040" class="method-signature">
1055
- <span class="method-name">absolute?</span><span class="method-args">()</span>
1056
- </a>
1057
- </div>
1058
-
1059
- <div class="method-description">
1060
- <p>
1061
- Returns true if this <a href="URI.html">URI</a> is known to be absolute.
1062
- </p>
1063
- <p><a class="source-toggle" href="#"
1064
- onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
1065
- <div class="method-source-code" id="M000040-source">
1066
- <pre>
1067
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 783</span>
1068
- 783: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">absolute?</span>
1069
- 784: <span class="ruby-keyword kw">return</span> <span class="ruby-operator">!</span><span class="ruby-identifier">relative?</span>
1070
- 785: <span class="ruby-keyword kw">end</span>
1071
- </pre>
1072
- </div>
1073
- </div>
1074
- </div>
1075
-
1076
- <div id="method-M000023" class="method-detail">
1077
- <a name="M000023"></a>
1078
-
1079
- <div class="method-heading">
1080
- <a href="#M000023" class="method-signature">
1081
- <span class="method-name">authority</span><span class="method-args">()</span>
1082
- </a>
1083
- </div>
1084
-
1085
- <div class="method-description">
1086
- <p>
1087
- Returns the <a href="URI.html#M000023">authority</a> segment of this <a
1088
- href="URI.html">URI</a>.
1089
- </p>
1090
- <p><a class="source-toggle" href="#"
1091
- onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
1092
- <div class="method-source-code" id="M000023-source">
1093
- <pre>
1094
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 617</span>
1095
- 617: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">authority</span>
1096
- 618: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-keyword kw">defined?</span>(<span class="ruby-ivar">@authority</span>) <span class="ruby-operator">||</span> <span class="ruby-ivar">@authority</span>.<span class="ruby-identifier">nil?</span>
1097
- 619: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">host</span>.<span class="ruby-identifier">nil?</span>
1098
- 620: <span class="ruby-ivar">@authority</span> = <span class="ruby-value str">&quot;&quot;</span>
1099
- 621: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">userinfo</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1100
- 622: <span class="ruby-ivar">@authority</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{self.userinfo}@&quot;</span>
1101
- 623: <span class="ruby-keyword kw">end</span>
1102
- 624: <span class="ruby-ivar">@authority</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">host</span>
1103
- 625: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">specified_port</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1104
- 626: <span class="ruby-ivar">@authority</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;:#{self.specified_port}&quot;</span>
1105
- 627: <span class="ruby-keyword kw">end</span>
1106
- 628: <span class="ruby-keyword kw">end</span>
1107
- 629: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@authority</span>
1108
- 630: <span class="ruby-keyword kw">end</span>
1109
- </pre>
1110
- </div>
1111
- </div>
1112
- </div>
1113
-
1114
- <div id="method-M000024" class="method-detail">
1115
- <a name="M000024"></a>
1116
-
1117
- <div class="method-heading">
1118
- <a href="#M000024" class="method-signature">
1119
- <span class="method-name">authority=</span><span class="method-args">(new_authority)</span>
1120
- </a>
1121
- </div>
1122
-
1123
- <div class="method-description">
1124
- <p>
1125
- Sets the <a href="URI.html#M000023">authority</a> segment of this <a
1126
- href="URI.html">URI</a>.
1127
- </p>
1128
- <p><a class="source-toggle" href="#"
1129
- onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
1130
- <div class="method-source-code" id="M000024-source">
1131
- <pre>
1132
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 633</span>
1133
- 633: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">authority=</span>(<span class="ruby-identifier">new_authority</span>)
1134
- 634: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_authority</span>
1135
- 635: <span class="ruby-identifier">new_userinfo</span> = <span class="ruby-identifier">new_authority</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/^([^\[\]]*)@/</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]
1136
- 636: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_userinfo</span>
1137
- 637: <span class="ruby-identifier">new_user</span> = <span class="ruby-identifier">new_userinfo</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/^([^:]*):?/</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]
1138
- 638: <span class="ruby-identifier">new_password</span> = <span class="ruby-identifier">new_userinfo</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/:(.*)$/</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]
1139
- 639: <span class="ruby-keyword kw">end</span>
1140
- 640: <span class="ruby-identifier">new_host</span> =
1141
- 641: <span class="ruby-identifier">new_authority</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/^([^\[\]]*)@/</span>, <span class="ruby-value str">&quot;&quot;</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/:([^:@\[\]]*?)$/</span>, <span class="ruby-value str">&quot;&quot;</span>)
1142
- 642: <span class="ruby-identifier">new_port</span> =
1143
- 643: <span class="ruby-identifier">new_authority</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/:([^:@\[\]]*?)$/</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]
1144
- 644: <span class="ruby-keyword kw">end</span>
1145
- 645:
1146
- 646: <span class="ruby-comment cmt"># Password assigned first to ensure validity in case of nil</span>
1147
- 647: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">password</span> = <span class="ruby-identifier">new_password</span>
1148
- 648: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">user</span> = <span class="ruby-identifier">new_user</span>
1149
- 649: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">host</span> = <span class="ruby-identifier">new_host</span>
1150
- 650:
1151
- 651: <span class="ruby-comment cmt"># Port reset to allow port normalization</span>
1152
- 652: <span class="ruby-ivar">@port</span> = <span class="ruby-keyword kw">nil</span>
1153
- 653: <span class="ruby-ivar">@specified_port</span> = <span class="ruby-identifier">new_port</span>
1154
- 654:
1155
- 655: <span class="ruby-comment cmt"># Ensure we haven't created an invalid URI</span>
1156
- 656: <span class="ruby-identifier">validate</span>()
1157
- 657: <span class="ruby-keyword kw">end</span>
1158
- </pre>
1159
- </div>
1160
- </div>
1161
- </div>
1162
-
1163
- <div id="method-M000032" class="method-detail">
1164
- <a name="M000032"></a>
1165
-
1166
- <div class="method-heading">
1167
- <a href="#M000032" class="method-signature">
1168
- <span class="method-name">basename</span><span class="method-args">()</span>
1169
- </a>
1170
- </div>
1171
-
1172
- <div class="method-description">
1173
- <p>
1174
- Returns the <a href="URI.html#M000032">basename</a>, if any, of the file at
1175
- the <a href="URI.html#M000030">path</a> being referenced. Returns nil if
1176
- there is no <a href="URI.html#M000030">path</a> component.
1177
- </p>
1178
- <p><a class="source-toggle" href="#"
1179
- onclick="toggleCode('M000032-source');return false;">[Source]</a></p>
1180
- <div class="method-source-code" id="M000032-source">
1181
- <pre>
1182
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 735</span>
1183
- 735: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">basename</span>
1184
- 736: <span class="ruby-comment cmt"># Path cannot be nil</span>
1185
- 737: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/;[^\/]*$/</span>, <span class="ruby-value str">&quot;&quot;</span>)
1186
- 738: <span class="ruby-keyword kw">end</span>
1187
- </pre>
1188
- </div>
1189
- </div>
1190
- </div>
1191
-
1192
- <div id="method-M000050" class="method-detail">
1193
- <a name="M000050"></a>
1194
-
1195
- <div class="method-heading">
1196
- <a href="#M000050" class="method-signature">
1197
- <span class="method-name">display_uri</span><span class="method-args">()</span>
1198
- </a>
1199
- </div>
1200
-
1201
- <div class="method-description">
1202
- <p>
1203
- Creates a <a href="URI.html">URI</a> suitable for display to users. If
1204
- semantic attacks are likely, the application should try to detect these and
1205
- warn the <a href="URI.html#M000015">user</a>. See RFC 3986 section 7.6 for
1206
- more information.
1207
- </p>
1208
- <p><a class="source-toggle" href="#"
1209
- onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
1210
- <div class="method-source-code" id="M000050-source">
1211
- <pre>
1212
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1033</span>
1213
- 1033: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">display_uri</span>
1214
- 1034: <span class="ruby-identifier">display_uri</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">normalize</span>
1215
- 1035: <span class="ruby-keyword kw">begin</span>
1216
- 1036: <span class="ruby-identifier">display_uri</span>.<span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-value str">&quot;@host&quot;</span>,
1217
- 1037: <span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">IDNA</span>.<span class="ruby-identifier">to_unicode</span>(<span class="ruby-identifier">display_uri</span>.<span class="ruby-identifier">host</span>))
1218
- 1038: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span>
1219
- 1039: <span class="ruby-keyword kw">nil</span>
1220
- 1040: <span class="ruby-keyword kw">end</span>
1221
- 1041: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">display_uri</span>
1222
- 1042: <span class="ruby-keyword kw">end</span>
1223
- </pre>
1224
- </div>
1225
- </div>
1226
- </div>
1227
-
1228
- <div id="method-M000054" class="method-detail">
1229
- <a name="M000054"></a>
1230
-
1231
- <div class="method-heading">
1232
- <a href="#M000054" class="method-signature">
1233
- <span class="method-name">dup</span><span class="method-args">()</span>
1234
- </a>
1235
- </div>
1236
-
1237
- <div class="method-description">
1238
- <p>
1239
- Clones the <a href="URI.html">URI</a> object.
1240
- </p>
1241
- <p><a class="source-toggle" href="#"
1242
- onclick="toggleCode('M000054-source');return false;">[Source]</a></p>
1243
- <div class="method-source-code" id="M000054-source">
1244
- <pre>
1245
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1075</span>
1246
- 1075: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dup</span>
1247
- 1076: <span class="ruby-identifier">duplicated_scheme</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme</span>.<span class="ruby-identifier">dup</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
1248
- 1077: <span class="ruby-identifier">duplicated_user</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">user</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">user</span>.<span class="ruby-identifier">dup</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
1249
- 1078: <span class="ruby-identifier">duplicated_password</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">password</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">password</span>.<span class="ruby-identifier">dup</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
1250
- 1079: <span class="ruby-identifier">duplicated_host</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">host</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">host</span>.<span class="ruby-identifier">dup</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
1251
- 1080: <span class="ruby-identifier">duplicated_port</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">specified_port</span>
1252
- 1081: <span class="ruby-identifier">duplicated_path</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span>.<span class="ruby-identifier">dup</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
1253
- 1082: <span class="ruby-identifier">duplicated_query</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">query</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">query</span>.<span class="ruby-identifier">dup</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
1254
- 1083: <span class="ruby-identifier">duplicated_fragment</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">fragment</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">fragment</span>.<span class="ruby-identifier">dup</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
1255
- 1084: <span class="ruby-identifier">duplicated_uri</span> = <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span>.<span class="ruby-identifier">new</span>(
1256
- 1085: <span class="ruby-identifier">duplicated_scheme</span>,
1257
- 1086: <span class="ruby-identifier">duplicated_user</span>,
1258
- 1087: <span class="ruby-identifier">duplicated_password</span>,
1259
- 1088: <span class="ruby-identifier">duplicated_host</span>,
1260
- 1089: <span class="ruby-identifier">duplicated_port</span>,
1261
- 1090: <span class="ruby-identifier">duplicated_path</span>,
1262
- 1091: <span class="ruby-identifier">duplicated_query</span>,
1263
- 1092: <span class="ruby-identifier">duplicated_fragment</span>
1264
- 1093: )
1265
- 1094: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">duplicated_uri</span>
1266
- 1095: <span class="ruby-keyword kw">end</span>
1267
- </pre>
1268
- </div>
1269
- </div>
1270
- </div>
1271
-
1272
- <div id="method-M000053" class="method-detail">
1273
- <a name="M000053"></a>
1274
-
1275
- <div class="method-heading">
1276
- <a href="#M000053" class="method-signature">
1277
- <span class="method-name">eql?</span><span class="method-args">(uri)</span>
1278
- </a>
1279
- </div>
1280
-
1281
- <div class="method-description">
1282
- <p>
1283
- Returns true if the <a href="URI.html">URI</a> objects are equal. This
1284
- method does NOT <a href="URI.html#M000048">normalize</a> either <a
1285
- href="URI.html">URI</a> before doing the comparison.
1286
- </p>
1287
- <p><a class="source-toggle" href="#"
1288
- onclick="toggleCode('M000053-source');return false;">[Source]</a></p>
1289
- <div class="method-source-code" id="M000053-source">
1290
- <pre>
1291
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1069</span>
1292
- 1069: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">eql?</span>(<span class="ruby-identifier">uri</span>)
1293
- 1070: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>)
1294
- 1071: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">to_s</span>
1295
- 1072: <span class="ruby-keyword kw">end</span>
1296
- </pre>
1297
- </div>
1298
- </div>
1299
- </div>
1300
-
1301
- <div id="method-M000033" class="method-detail">
1302
- <a name="M000033"></a>
1303
-
1304
- <div class="method-heading">
1305
- <a href="#M000033" class="method-signature">
1306
- <span class="method-name">extname</span><span class="method-args">()</span>
1307
- </a>
1308
- </div>
1309
-
1310
- <div class="method-description">
1311
- <p>
1312
- Returns the extension, if any, of the file at the <a
1313
- href="URI.html#M000030">path</a> being referenced. Returns &quot;&quot; if
1314
- there is no extension or nil if there is no <a
1315
- href="URI.html#M000030">path</a> component.
1316
- </p>
1317
- <p><a class="source-toggle" href="#"
1318
- onclick="toggleCode('M000033-source');return false;">[Source]</a></p>
1319
- <div class="method-source-code" id="M000033-source">
1320
- <pre>
1321
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 743</span>
1322
- 743: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">extname</span>
1323
- 744: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span>
1324
- 745: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">extname</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">basename</span>)
1325
- 746: <span class="ruby-keyword kw">end</span>
1326
- </pre>
1327
- </div>
1328
- </div>
1329
- </div>
1330
-
1331
- <div id="method-M000005" class="method-detail">
1332
- <a name="M000005"></a>
1333
-
1334
- <div class="method-heading">
1335
- <a href="#M000005" class="method-signature">
1336
- <span class="method-name">extract_mapping</span><span class="method-args">(pattern, processor=nil)</span>
1337
- </a>
1338
- </div>
1339
-
1340
- <div class="method-description">
1341
- <p>
1342
- Extracts a mapping from the <a href="URI.html">URI</a> using a <a
1343
- href="URI.html">URI</a> Template pattern. Returns nil if the pattern
1344
- doesn&#8216;t match the <a href="URI.html">URI</a>.
1345
- </p>
1346
- <p>
1347
- An optional processor object may be supplied. The object should respond to
1348
- either the :restore or :match messages or both. The :restore method should
1349
- take two parameters: :name and :value. The :restore method should reverse
1350
- any transformations that have been performed on the value to ensure a valid
1351
- <a href="URI.html">URI</a>. The :match method should take a single
1352
- parameter: :name. The :match method should return a String containing a
1353
- regular expression capture group for matching on that particular variable.
1354
- The default value is &quot;.*&quot;.
1355
- </p>
1356
- <p>
1357
- An example:
1358
- </p>
1359
- <pre>
1360
- class ExampleProcessor
1361
- def self.restore(name, value)
1362
- return value.gsub(/\+/, &quot; &quot;) if name == &quot;query&quot;
1363
- return value
1364
- end
1365
-
1366
- def self.match(name)
1367
- return &quot;.*?&quot; if name == &quot;first&quot;
1368
- return &quot;.*&quot;
1369
- end
1370
- end
1371
-
1372
- uri = Addressable::URI.parse(
1373
- &quot;http://example.com/search/an+example+search+query/&quot;)
1374
- uri.extract_mapping(&quot;http://example.com/search/{query}/&quot;,
1375
- ExampleProcessor)
1376
- =&gt; {&quot;query&quot; =&gt; &quot;an example search query&quot;}
1377
-
1378
- uri = Addressable::URI.parse(
1379
- &quot;http://example.com/a/b/c/&quot;)
1380
- uri.extract_mapping(&quot;http://example.com/{first}/{second}/&quot;,
1381
- ExampleProcessor)
1382
- =&gt; {&quot;first&quot; =&gt; &quot;a&quot;, &quot;second&quot; =&gt; &quot;b/c&quot;}
1383
- </pre>
1384
- <p><a class="source-toggle" href="#"
1385
- onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
1386
- <div class="method-source-code" id="M000005-source">
1387
- <pre>
1388
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 267</span>
1389
- 267: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">extract_mapping</span>(<span class="ruby-identifier">pattern</span>, <span class="ruby-identifier">processor</span>=<span class="ruby-keyword kw">nil</span>)
1390
- 268: <span class="ruby-identifier">mapping</span> = {}
1391
- 269: <span class="ruby-identifier">variable_regexp</span> =
1392
- 270: <span class="ruby-node">/\{([#{Addressable::URI::CharacterClasses::UNRESERVED}]+)\}/</span>
1393
- 271:
1394
- 272: <span class="ruby-comment cmt"># Get all the variables in the pattern</span>
1395
- 273: <span class="ruby-identifier">variables</span> = <span class="ruby-identifier">pattern</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-identifier">variable_regexp</span>).<span class="ruby-identifier">flatten</span>
1396
- 274:
1397
- 275: <span class="ruby-comment cmt"># Initialize all result values to the empty string</span>
1398
- 276: <span class="ruby-identifier">variables</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">mapping</span>[<span class="ruby-identifier">v</span>] = <span class="ruby-value str">&quot;&quot;</span> }
1399
- 277:
1400
- 278: <span class="ruby-comment cmt"># Escape the pattern</span>
1401
- 279: <span class="ruby-identifier">escaped_pattern</span> =
1402
- 280: <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">pattern</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/\\\{/</span>, <span class="ruby-value str">&quot;{&quot;</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/\\\}/</span>, <span class="ruby-value str">&quot;}&quot;</span>)
1403
- 281:
1404
- 282: <span class="ruby-comment cmt"># Create a regular expression that captures the values of the</span>
1405
- 283: <span class="ruby-comment cmt"># variables in the URI.</span>
1406
- 284: <span class="ruby-identifier">regexp_string</span> = <span class="ruby-identifier">escaped_pattern</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-identifier">variable_regexp</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
1407
- 285: <span class="ruby-identifier">capture_group</span> = <span class="ruby-value str">&quot;(.*)&quot;</span>
1408
- 286:
1409
- 287: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">processor</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1410
- 288: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">processor</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:match</span>)
1411
- 289: <span class="ruby-identifier">name</span> = <span class="ruby-identifier">v</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-identifier">variable_regexp</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]
1412
- 290: <span class="ruby-identifier">capture_group</span> = <span class="ruby-node">&quot;(#{processor.match(name)})&quot;</span>
1413
- 291: <span class="ruby-keyword kw">end</span>
1414
- 292: <span class="ruby-keyword kw">end</span>
1415
- 293:
1416
- 294: <span class="ruby-identifier">capture_group</span>
1417
- 295: <span class="ruby-keyword kw">end</span>
1418
- 296:
1419
- 297: <span class="ruby-comment cmt"># Ensure that the regular expression matches the whole URI.</span>
1420
- 298: <span class="ruby-identifier">regexp_string</span> = <span class="ruby-node">&quot;^#{regexp_string}$&quot;</span>
1421
- 299:
1422
- 300: <span class="ruby-identifier">regexp</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">regexp_string</span>)
1423
- 301: <span class="ruby-identifier">values</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-identifier">regexp</span>).<span class="ruby-identifier">flatten</span>
1424
- 302:
1425
- 303: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">variables</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">values</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">variables</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
1426
- 304: <span class="ruby-comment cmt"># We have a match.</span>
1427
- 305: <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword kw">in</span> <span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">variables</span>.<span class="ruby-identifier">size</span>
1428
- 306: <span class="ruby-identifier">name</span> = <span class="ruby-identifier">variables</span>[<span class="ruby-identifier">i</span>]
1429
- 307: <span class="ruby-identifier">value</span> = <span class="ruby-identifier">values</span>[<span class="ruby-identifier">i</span>]
1430
- 308:
1431
- 309: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">processor</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1432
- 310: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">processor</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:restore</span>)
1433
- 311: <span class="ruby-identifier">value</span> = <span class="ruby-identifier">processor</span>.<span class="ruby-identifier">restore</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>)
1434
- 312: <span class="ruby-keyword kw">end</span>
1435
- 313: <span class="ruby-keyword kw">end</span>
1436
- 314:
1437
- 315: <span class="ruby-identifier">mapping</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-identifier">value</span>
1438
- 316: <span class="ruby-keyword kw">end</span>
1439
- 317: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">mapping</span>
1440
- 318: <span class="ruby-keyword kw">elsif</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">pattern</span>
1441
- 319: <span class="ruby-comment cmt"># The pattern contained no variables but still matched.</span>
1442
- 320: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">mapping</span>
1443
- 321: <span class="ruby-keyword kw">else</span>
1444
- 322: <span class="ruby-comment cmt"># Pattern failed to match URI.</span>
1445
- 323: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
1446
- 324: <span class="ruby-keyword kw">end</span>
1447
- 325: <span class="ruby-keyword kw">end</span>
1448
- </pre>
1449
- </div>
1450
- </div>
1451
- </div>
1452
-
1453
- <div id="method-M000036" class="method-detail">
1454
- <a name="M000036"></a>
1455
-
1456
- <div class="method-heading">
1457
- <a href="#M000036" class="method-signature">
1458
- <span class="method-name">fragment</span><span class="method-args">()</span>
1459
- </a>
1460
- </div>
1461
-
1462
- <div class="method-description">
1463
- <p>
1464
- Returns the <a href="URI.html#M000036">fragment</a> for this <a
1465
- href="URI.html">URI</a>.
1466
- </p>
1467
- <p><a class="source-toggle" href="#"
1468
- onclick="toggleCode('M000036-source');return false;">[Source]</a></p>
1469
- <div class="method-source-code" id="M000036-source">
1470
- <pre>
1471
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 759</span>
1472
- 759: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fragment</span>
1473
- 760: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@fragment</span>
1474
- 761: <span class="ruby-keyword kw">end</span>
1475
- </pre>
1476
- </div>
1477
- </div>
1478
- </div>
1479
-
1480
- <div id="method-M000037" class="method-detail">
1481
- <a name="M000037"></a>
1482
-
1483
- <div class="method-heading">
1484
- <a href="#M000037" class="method-signature">
1485
- <span class="method-name">fragment=</span><span class="method-args">(new_fragment)</span>
1486
- </a>
1487
- </div>
1488
-
1489
- <div class="method-description">
1490
- <p>
1491
- Sets the <a href="URI.html#M000036">fragment</a> for this <a
1492
- href="URI.html">URI</a>.
1493
- </p>
1494
- <p><a class="source-toggle" href="#"
1495
- onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
1496
- <div class="method-source-code" id="M000037-source">
1497
- <pre>
1498
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 764</span>
1499
- 764: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fragment=</span>(<span class="ruby-identifier">new_fragment</span>)
1500
- 765: <span class="ruby-ivar">@fragment</span> = <span class="ruby-identifier">new_fragment</span>
1501
- 766: <span class="ruby-keyword kw">end</span>
1502
- </pre>
1503
- </div>
1504
- </div>
1505
- </div>
1506
-
1507
- <div id="method-M000021" class="method-detail">
1508
- <a name="M000021"></a>
1509
-
1510
- <div class="method-heading">
1511
- <a href="#M000021" class="method-signature">
1512
- <span class="method-name">host</span><span class="method-args">()</span>
1513
- </a>
1514
- </div>
1515
-
1516
- <div class="method-description">
1517
- <p>
1518
- Returns the <a href="URI.html#M000021">host</a> for this <a
1519
- href="URI.html">URI</a>.
1520
- </p>
1521
- <p><a class="source-toggle" href="#"
1522
- onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
1523
- <div class="method-source-code" id="M000021-source">
1524
- <pre>
1525
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 601</span>
1526
- 601: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">host</span>
1527
- 602: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@host</span>
1528
- 603: <span class="ruby-keyword kw">end</span>
1529
- </pre>
1530
- </div>
1531
- </div>
1532
- </div>
1533
-
1534
- <div id="method-M000022" class="method-detail">
1535
- <a name="M000022"></a>
1536
-
1537
- <div class="method-heading">
1538
- <a href="#M000022" class="method-signature">
1539
- <span class="method-name">host=</span><span class="method-args">(new_host)</span>
1540
- </a>
1541
- </div>
1542
-
1543
- <div class="method-description">
1544
- <p>
1545
- Sets the <a href="URI.html#M000021">host</a> for this <a
1546
- href="URI.html">URI</a>.
1547
- </p>
1548
- <p><a class="source-toggle" href="#"
1549
- onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
1550
- <div class="method-source-code" id="M000022-source">
1551
- <pre>
1552
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 606</span>
1553
- 606: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">host=</span>(<span class="ruby-identifier">new_host</span>)
1554
- 607: <span class="ruby-ivar">@host</span> = <span class="ruby-identifier">new_host</span>
1555
- 608:
1556
- 609: <span class="ruby-comment cmt"># Reset dependant values</span>
1557
- 610: <span class="ruby-ivar">@authority</span> = <span class="ruby-keyword kw">nil</span>
1558
- 611:
1559
- 612: <span class="ruby-comment cmt"># Ensure we haven't created an invalid URI</span>
1560
- 613: <span class="ruby-identifier">validate</span>()
1561
- 614: <span class="ruby-keyword kw">end</span>
1562
- </pre>
1563
- </div>
1564
- </div>
1565
- </div>
1566
-
1567
- <div id="method-M000057" class="method-detail">
1568
- <a name="M000057"></a>
1569
-
1570
- <div class="method-heading">
1571
- <a href="#M000057" class="method-signature">
1572
- <span class="method-name">inspect</span><span class="method-args">()</span>
1573
- </a>
1574
- </div>
1575
-
1576
- <div class="method-description">
1577
- <p>
1578
- Returns a string representation of the <a href="URI.html">URI</a>
1579
- object&#8216;s state.
1580
- </p>
1581
- <p><a class="source-toggle" href="#"
1582
- onclick="toggleCode('M000057-source');return false;">[Source]</a></p>
1583
- <div class="method-source-code" id="M000057-source">
1584
- <pre>
1585
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1123</span>
1586
- 1123: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inspect</span>
1587
- 1124: <span class="ruby-identifier">sprintf</span>(<span class="ruby-value str">&quot;#&lt;%s:%#0x URI:%s&gt;&quot;</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">object_id</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>)
1588
- 1125: <span class="ruby-keyword kw">end</span>
1589
- </pre>
1590
- </div>
1591
- </div>
1592
- </div>
1593
-
1594
- <div id="method-M000038" class="method-detail">
1595
- <a name="M000038"></a>
1596
-
1597
- <div class="method-heading">
1598
- <a href="#M000038" class="method-signature">
1599
- <span class="method-name">ip_based?</span><span class="method-args">()</span>
1600
- </a>
1601
- </div>
1602
-
1603
- <div class="method-description">
1604
- <p>
1605
- Returns true if the <a href="URI.html">URI</a> uses an IP-based protocol.
1606
- </p>
1607
- <p><a class="source-toggle" href="#"
1608
- onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
1609
- <div class="method-source-code" id="M000038-source">
1610
- <pre>
1611
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 769</span>
1612
- 769: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ip_based?</span>
1613
- 770: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme</span>
1614
- 771: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">ip_based_schemes</span>.<span class="ruby-identifier">include?</span>(
1615
- 772: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">downcase</span>)
1616
- 773: <span class="ruby-keyword kw">end</span>
1617
- 774: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
1618
- 775: <span class="ruby-keyword kw">end</span>
1619
- </pre>
1620
- </div>
1621
- </div>
1622
- </div>
1623
-
1624
- <div id="method-M000043" class="method-detail">
1625
- <a name="M000043"></a>
1626
-
1627
- <div class="method-heading">
1628
- <span class="method-name">join</span><span class="method-args">(uri)</span>
1629
- </div>
1630
-
1631
- <div class="method-description">
1632
- <p>
1633
- Alias for <a href="URI.html#M000042">merge</a>
1634
- </p>
1635
- </div>
1636
- </div>
1637
-
1638
- <div id="method-M000045" class="method-detail">
1639
- <a name="M000045"></a>
1640
-
1641
- <div class="method-heading">
1642
- <span class="method-name">join!</span><span class="method-args">(uri)</span>
1643
- </div>
1644
-
1645
- <div class="method-description">
1646
- <p>
1647
- Alias for <a href="URI.html#M000042">merge</a>!
1648
- </p>
1649
- </div>
1650
- </div>
1651
-
1652
- <div id="method-M000042" class="method-detail">
1653
- <a name="M000042"></a>
1654
-
1655
- <div class="method-heading">
1656
- <a href="#M000042" class="method-signature">
1657
- <span class="method-name">merge</span><span class="method-args">(uri)</span>
1658
- </a>
1659
- </div>
1660
-
1661
- <div class="method-description">
1662
- <p>
1663
- Merges two URIs together.
1664
- </p>
1665
- <p><a class="source-toggle" href="#"
1666
- onclick="toggleCode('M000042-source');return false;">[Source]</a></p>
1667
- <div class="method-source-code" id="M000042-source">
1668
- <pre>
1669
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 879</span>
1670
- 879: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">merge</span>(<span class="ruby-identifier">uri</span>)
1671
- 880: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">uri</span>
1672
- 881: <span class="ruby-keyword kw">end</span>
1673
- </pre>
1674
- </div>
1675
- </div>
1676
- </div>
1677
-
1678
- <div id="method-M000044" class="method-detail">
1679
- <a name="M000044"></a>
1680
-
1681
- <div class="method-heading">
1682
- <a href="#M000044" class="method-signature">
1683
- <span class="method-name">merge!</span><span class="method-args">(uri)</span>
1684
- </a>
1685
- </div>
1686
-
1687
- <div class="method-description">
1688
- <p>
1689
- Destructive form of <a href="URI.html#M000042">merge</a>.
1690
- </p>
1691
- <p><a class="source-toggle" href="#"
1692
- onclick="toggleCode('M000044-source');return false;">[Source]</a></p>
1693
- <div class="method-source-code" id="M000044-source">
1694
- <pre>
1695
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 885</span>
1696
- 885: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">uri</span>)
1697
- 886: <span class="ruby-identifier">replace_self</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">uri</span>))
1698
- 887: <span class="ruby-keyword kw">end</span>
1699
- </pre>
1700
- </div>
1701
- </div>
1702
- </div>
1703
-
1704
- <div id="method-M000048" class="method-detail">
1705
- <a name="M000048"></a>
1706
-
1707
- <div class="method-heading">
1708
- <a href="#M000048" class="method-signature">
1709
- <span class="method-name">normalize</span><span class="method-args">()</span>
1710
- </a>
1711
- </div>
1712
-
1713
- <div class="method-description">
1714
- <p>
1715
- Returns a normalized <a href="URI.html">URI</a> object.
1716
- </p>
1717
- <p>
1718
- NOTE: This method does not attempt to fully conform to specifications. It
1719
- exists largely to correct other people&#8216;s failures to read the
1720
- specifications, and also to deal with caching issues since several
1721
- different URIs may represent the same resource and should not be cached
1722
- multiple times.
1723
- </p>
1724
- <p><a class="source-toggle" href="#"
1725
- onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
1726
- <div class="method-source-code" id="M000048-source">
1727
- <pre>
1728
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 956</span>
1729
- 956: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">normalize</span>
1730
- 957: <span class="ruby-identifier">normalized_scheme</span> = <span class="ruby-keyword kw">nil</span>
1731
- 958: <span class="ruby-identifier">normalized_scheme</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1732
- 959: <span class="ruby-identifier">normalized_scheme</span> = <span class="ruby-value str">&quot;svn+ssh&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">normalized_scheme</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;ssh+svn&quot;</span>
1733
- 960: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">normalized_scheme</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;feed&quot;</span>
1734
- 961: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^feed:\/*http:\/*/</span>
1735
- 962: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">parse</span>(
1736
- 963: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/^feed:\/*(http:\/*.*)/</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]).<span class="ruby-identifier">normalize</span>
1737
- 964: <span class="ruby-keyword kw">end</span>
1738
- 965: <span class="ruby-keyword kw">end</span>
1739
- 966: <span class="ruby-identifier">normalized_user</span> = <span class="ruby-keyword kw">nil</span>
1740
- 967: <span class="ruby-identifier">normalized_user</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">user</span>.<span class="ruby-identifier">strip</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">user</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1741
- 968: <span class="ruby-identifier">normalized_password</span> = <span class="ruby-keyword kw">nil</span>
1742
- 969: <span class="ruby-identifier">normalized_password</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">password</span>.<span class="ruby-identifier">strip</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">password</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1743
- 970:
1744
- 971: <span class="ruby-comment cmt"># If we are using http or https and user/password are blank,</span>
1745
- 972: <span class="ruby-comment cmt"># then we remove them</span>
1746
- 973: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">normalized_scheme</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/https?/</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">normalized_user</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span> <span class="ruby-operator">&amp;&amp;</span>
1747
- 974: (<span class="ruby-operator">!</span><span class="ruby-identifier">normalized_password</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">normalized_password</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span>)
1748
- 975: <span class="ruby-identifier">normalized_user</span> = <span class="ruby-keyword kw">nil</span>
1749
- 976: <span class="ruby-identifier">normalized_password</span> = <span class="ruby-keyword kw">nil</span>
1750
- 977: <span class="ruby-keyword kw">end</span>
1751
- 978:
1752
- 979: <span class="ruby-identifier">normalized_host</span> = <span class="ruby-keyword kw">nil</span>
1753
- 980: <span class="ruby-identifier">normalized_host</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">host</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">host</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1754
- 981: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">normalized_host</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1755
- 982: <span class="ruby-keyword kw">begin</span>
1756
- 983: <span class="ruby-identifier">normalized_host</span> = <span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">IDNA</span>.<span class="ruby-identifier">to_ascii</span>(<span class="ruby-identifier">normalized_host</span>)
1757
- 984: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span>
1758
- 985: <span class="ruby-keyword kw">nil</span>
1759
- 986: <span class="ruby-keyword kw">end</span>
1760
- 987: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">normalized_host</span>[<span class="ruby-value">-1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;.&quot;</span>
1761
- 988: <span class="ruby-identifier">normalized_host</span> = <span class="ruby-identifier">normalized_host</span>[<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-value">-1</span>]
1762
- 989: <span class="ruby-keyword kw">end</span>
1763
- 990: <span class="ruby-keyword kw">end</span>
1764
- 991:
1765
- 992: <span class="ruby-identifier">normalized_port</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">port</span>
1766
- 993: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">scheme_mapping</span>[<span class="ruby-identifier">normalized_scheme</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">normalized_port</span>
1767
- 994: <span class="ruby-identifier">normalized_port</span> = <span class="ruby-keyword kw">nil</span>
1768
- 995: <span class="ruby-keyword kw">end</span>
1769
- 996: <span class="ruby-identifier">normalized_path</span> = <span class="ruby-keyword kw">nil</span>
1770
- 997: <span class="ruby-identifier">normalized_path</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span>.<span class="ruby-identifier">strip</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1771
- 998: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">normalized_path</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1772
- 999: <span class="ruby-identifier">normalized_path</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">normalize_path</span>(<span class="ruby-identifier">normalized_path</span>)
1773
- 1000: <span class="ruby-keyword kw">end</span>
1774
- 1001: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">normalized_path</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span>
1775
- 1002: <span class="ruby-keyword kw">if</span> [<span class="ruby-value str">&quot;http&quot;</span>, <span class="ruby-value str">&quot;https&quot;</span>, <span class="ruby-value str">&quot;ftp&quot;</span>, <span class="ruby-value str">&quot;tftp&quot;</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">normalized_scheme</span>)
1776
- 1003: <span class="ruby-identifier">normalized_path</span> = <span class="ruby-value str">&quot;/&quot;</span>
1777
- 1004: <span class="ruby-keyword kw">end</span>
1778
- 1005: <span class="ruby-keyword kw">end</span>
1779
- 1006:
1780
- 1007: <span class="ruby-identifier">normalized_query</span> = <span class="ruby-keyword kw">nil</span>
1781
- 1008: <span class="ruby-identifier">normalized_query</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">query</span>.<span class="ruby-identifier">strip</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">query</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1782
- 1009:
1783
- 1010: <span class="ruby-identifier">normalized_fragment</span> = <span class="ruby-keyword kw">nil</span>
1784
- 1011: <span class="ruby-identifier">normalized_fragment</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">fragment</span>.<span class="ruby-identifier">strip</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">fragment</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1785
- 1012: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(
1786
- 1013: <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span>.<span class="ruby-identifier">normalized_encode</span>(<span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span>.<span class="ruby-identifier">new</span>(
1787
- 1014: <span class="ruby-identifier">normalized_scheme</span>,
1788
- 1015: <span class="ruby-identifier">normalized_user</span>,
1789
- 1016: <span class="ruby-identifier">normalized_password</span>,
1790
- 1017: <span class="ruby-identifier">normalized_host</span>,
1791
- 1018: <span class="ruby-identifier">normalized_port</span>,
1792
- 1019: <span class="ruby-identifier">normalized_path</span>,
1793
- 1020: <span class="ruby-identifier">normalized_query</span>,
1794
- 1021: <span class="ruby-identifier">normalized_fragment</span>
1795
- 1022: )))
1796
- 1023: <span class="ruby-keyword kw">end</span>
1797
- </pre>
1798
- </div>
1799
- </div>
1800
- </div>
1801
-
1802
- <div id="method-M000049" class="method-detail">
1803
- <a name="M000049"></a>
1804
-
1805
- <div class="method-heading">
1806
- <a href="#M000049" class="method-signature">
1807
- <span class="method-name">normalize!</span><span class="method-args">()</span>
1808
- </a>
1809
- </div>
1810
-
1811
- <div class="method-description">
1812
- <p>
1813
- Destructively normalizes this <a href="URI.html">URI</a> object.
1814
- </p>
1815
- <p><a class="source-toggle" href="#"
1816
- onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
1817
- <div class="method-source-code" id="M000049-source">
1818
- <pre>
1819
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1026</span>
1820
- 1026: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">normalize!</span>
1821
- 1027: <span class="ruby-identifier">replace_self</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">normalize</span>)
1822
- 1028: <span class="ruby-keyword kw">end</span>
1823
- </pre>
1824
- </div>
1825
- </div>
1826
- </div>
1827
-
1828
- <div id="method-M000017" class="method-detail">
1829
- <a name="M000017"></a>
1830
-
1831
- <div class="method-heading">
1832
- <a href="#M000017" class="method-signature">
1833
- <span class="method-name">password</span><span class="method-args">()</span>
1834
- </a>
1835
- </div>
1836
-
1837
- <div class="method-description">
1838
- <p>
1839
- Returns the <a href="URI.html#M000017">password</a> for this <a
1840
- href="URI.html">URI</a>.
1841
- </p>
1842
- <p><a class="source-toggle" href="#"
1843
- onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
1844
- <div class="method-source-code" id="M000017-source">
1845
- <pre>
1846
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 547</span>
1847
- 547: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">password</span>
1848
- 548: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@password</span>
1849
- 549: <span class="ruby-keyword kw">end</span>
1850
- </pre>
1851
- </div>
1852
- </div>
1853
- </div>
1854
-
1855
- <div id="method-M000018" class="method-detail">
1856
- <a name="M000018"></a>
1857
-
1858
- <div class="method-heading">
1859
- <a href="#M000018" class="method-signature">
1860
- <span class="method-name">password=</span><span class="method-args">(new_password)</span>
1861
- </a>
1862
- </div>
1863
-
1864
- <div class="method-description">
1865
- <p>
1866
- Sets the <a href="URI.html#M000017">password</a> for this <a
1867
- href="URI.html">URI</a>.
1868
- </p>
1869
- <p><a class="source-toggle" href="#"
1870
- onclick="toggleCode('M000018-source');return false;">[Source]</a></p>
1871
- <div class="method-source-code" id="M000018-source">
1872
- <pre>
1873
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 552</span>
1874
- 552: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">password=</span>(<span class="ruby-identifier">new_password</span>)
1875
- 553: <span class="ruby-ivar">@password</span> = <span class="ruby-identifier">new_password</span>
1876
- 554:
1877
- 555: <span class="ruby-comment cmt"># You can't have a nil user with a non-nil password</span>
1878
- 556: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@password</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
1879
- 557: <span class="ruby-ivar">@user</span> = <span class="ruby-value str">&quot;&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">nil?</span>
1880
- 558: <span class="ruby-keyword kw">end</span>
1881
- 559:
1882
- 560: <span class="ruby-comment cmt"># Reset dependant values</span>
1883
- 561: <span class="ruby-ivar">@userinfo</span> = <span class="ruby-keyword kw">nil</span>
1884
- 562: <span class="ruby-ivar">@authority</span> = <span class="ruby-keyword kw">nil</span>
1885
- 563:
1886
- 564: <span class="ruby-comment cmt"># Ensure we haven't created an invalid URI</span>
1887
- 565: <span class="ruby-identifier">validate</span>()
1888
- 566: <span class="ruby-keyword kw">end</span>
1889
- </pre>
1890
- </div>
1891
- </div>
1892
- </div>
1893
-
1894
- <div id="method-M000030" class="method-detail">
1895
- <a name="M000030"></a>
1896
-
1897
- <div class="method-heading">
1898
- <a href="#M000030" class="method-signature">
1899
- <span class="method-name">path</span><span class="method-args">()</span>
1900
- </a>
1901
- </div>
1902
-
1903
- <div class="method-description">
1904
- <p>
1905
- Returns the <a href="URI.html#M000030">path</a> for this <a
1906
- href="URI.html">URI</a>.
1907
- </p>
1908
- <p><a class="source-toggle" href="#"
1909
- onclick="toggleCode('M000030-source');return false;">[Source]</a></p>
1910
- <div class="method-source-code" id="M000030-source">
1911
- <pre>
1912
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 724</span>
1913
- 724: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">path</span>
1914
- 725: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@path</span>
1915
- 726: <span class="ruby-keyword kw">end</span>
1916
- </pre>
1917
- </div>
1918
- </div>
1919
- </div>
1920
-
1921
- <div id="method-M000031" class="method-detail">
1922
- <a name="M000031"></a>
1923
-
1924
- <div class="method-heading">
1925
- <a href="#M000031" class="method-signature">
1926
- <span class="method-name">path=</span><span class="method-args">(new_path)</span>
1927
- </a>
1928
- </div>
1929
-
1930
- <div class="method-description">
1931
- <p>
1932
- Sets the <a href="URI.html#M000030">path</a> for this <a
1933
- href="URI.html">URI</a>.
1934
- </p>
1935
- <p><a class="source-toggle" href="#"
1936
- onclick="toggleCode('M000031-source');return false;">[Source]</a></p>
1937
- <div class="method-source-code" id="M000031-source">
1938
- <pre>
1939
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 729</span>
1940
- 729: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">path=</span>(<span class="ruby-identifier">new_path</span>)
1941
- 730: <span class="ruby-ivar">@path</span> = (<span class="ruby-identifier">new_path</span> <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;&quot;</span>)
1942
- 731: <span class="ruby-keyword kw">end</span>
1943
- </pre>
1944
- </div>
1945
- </div>
1946
- </div>
1947
-
1948
- <div id="method-M000027" class="method-detail">
1949
- <a name="M000027"></a>
1950
-
1951
- <div class="method-heading">
1952
- <a href="#M000027" class="method-signature">
1953
- <span class="method-name">port</span><span class="method-args">()</span>
1954
- </a>
1955
- </div>
1956
-
1957
- <div class="method-description">
1958
- <p>
1959
- Returns the <a href="URI.html#M000027">port</a> number for this <a
1960
- href="URI.html">URI</a>. This method will <a
1961
- href="URI.html#M000048">normalize</a> to the default <a
1962
- href="URI.html#M000027">port</a> for the <a href="URI.html">URI</a>&#8216;s
1963
- <a href="URI.html#M000013">scheme</a> if the <a
1964
- href="URI.html#M000027">port</a> isn&#8216;t explicitly specified in the <a
1965
- href="URI.html">URI</a>.
1966
- </p>
1967
- <p><a class="source-toggle" href="#"
1968
- onclick="toggleCode('M000027-source');return false;">[Source]</a></p>
1969
- <div class="method-source-code" id="M000027-source">
1970
- <pre>
1971
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 692</span>
1972
- 692: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">port</span>
1973
- 693: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@port</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
1974
- 694: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme</span>
1975
- 695: <span class="ruby-ivar">@port</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">scheme_mapping</span>[<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">downcase</span>]
1976
- 696: <span class="ruby-keyword kw">else</span>
1977
- 697: <span class="ruby-ivar">@port</span> = <span class="ruby-keyword kw">nil</span>
1978
- 698: <span class="ruby-keyword kw">end</span>
1979
- 699: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@port</span>
1980
- 700: <span class="ruby-keyword kw">else</span>
1981
- 701: <span class="ruby-ivar">@port</span> = <span class="ruby-ivar">@port</span>.<span class="ruby-identifier">to_i</span>
1982
- 702: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@port</span>
1983
- 703: <span class="ruby-keyword kw">end</span>
1984
- 704: <span class="ruby-keyword kw">end</span>
1985
- </pre>
1986
- </div>
1987
- </div>
1988
- </div>
1989
-
1990
- <div id="method-M000028" class="method-detail">
1991
- <a name="M000028"></a>
1992
-
1993
- <div class="method-heading">
1994
- <a href="#M000028" class="method-signature">
1995
- <span class="method-name">port=</span><span class="method-args">(new_port)</span>
1996
- </a>
1997
- </div>
1998
-
1999
- <div class="method-description">
2000
- <p>
2001
- Sets the <a href="URI.html#M000027">port</a> for this <a
2002
- href="URI.html">URI</a>.
2003
- </p>
2004
- <p><a class="source-toggle" href="#"
2005
- onclick="toggleCode('M000028-source');return false;">[Source]</a></p>
2006
- <div class="method-source-code" id="M000028-source">
2007
- <pre>
2008
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 707</span>
2009
- 707: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">port=</span>(<span class="ruby-identifier">new_port</span>)
2010
- 708: <span class="ruby-ivar">@port</span> = <span class="ruby-identifier">new_port</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">to_i</span>
2011
- 709: <span class="ruby-ivar">@specified_port</span> = <span class="ruby-ivar">@port</span>
2012
- 710: <span class="ruby-ivar">@authority</span> = <span class="ruby-keyword kw">nil</span>
2013
- 711: <span class="ruby-keyword kw">end</span>
2014
- </pre>
2015
- </div>
2016
- </div>
2017
- </div>
2018
-
2019
- <div id="method-M000034" class="method-detail">
2020
- <a name="M000034"></a>
2021
-
2022
- <div class="method-heading">
2023
- <a href="#M000034" class="method-signature">
2024
- <span class="method-name">query</span><span class="method-args">()</span>
2025
- </a>
2026
- </div>
2027
-
2028
- <div class="method-description">
2029
- <p>
2030
- Returns the <a href="URI.html#M000034">query</a> string for this <a
2031
- href="URI.html">URI</a>.
2032
- </p>
2033
- <p><a class="source-toggle" href="#"
2034
- onclick="toggleCode('M000034-source');return false;">[Source]</a></p>
2035
- <div class="method-source-code" id="M000034-source">
2036
- <pre>
2037
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 749</span>
2038
- 749: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">query</span>
2039
- 750: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@query</span>
2040
- 751: <span class="ruby-keyword kw">end</span>
2041
- </pre>
2042
- </div>
2043
- </div>
2044
- </div>
2045
-
2046
- <div id="method-M000035" class="method-detail">
2047
- <a name="M000035"></a>
2048
-
2049
- <div class="method-heading">
2050
- <a href="#M000035" class="method-signature">
2051
- <span class="method-name">query=</span><span class="method-args">(new_query)</span>
2052
- </a>
2053
- </div>
2054
-
2055
- <div class="method-description">
2056
- <p>
2057
- Sets the <a href="URI.html#M000034">query</a> string for this <a
2058
- href="URI.html">URI</a>.
2059
- </p>
2060
- <p><a class="source-toggle" href="#"
2061
- onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
2062
- <div class="method-source-code" id="M000035-source">
2063
- <pre>
2064
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 754</span>
2065
- 754: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">query=</span>(<span class="ruby-identifier">new_query</span>)
2066
- 755: <span class="ruby-ivar">@query</span> = <span class="ruby-identifier">new_query</span>
2067
- 756: <span class="ruby-keyword kw">end</span>
2068
- </pre>
2069
- </div>
2070
- </div>
2071
- </div>
2072
-
2073
- <div id="method-M000039" class="method-detail">
2074
- <a name="M000039"></a>
2075
-
2076
- <div class="method-heading">
2077
- <a href="#M000039" class="method-signature">
2078
- <span class="method-name">relative?</span><span class="method-args">()</span>
2079
- </a>
2080
- </div>
2081
-
2082
- <div class="method-description">
2083
- <p>
2084
- Returns true if this <a href="URI.html">URI</a> is known to be relative.
2085
- </p>
2086
- <p><a class="source-toggle" href="#"
2087
- onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
2088
- <div class="method-source-code" id="M000039-source">
2089
- <pre>
2090
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 778</span>
2091
- 778: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">relative?</span>
2092
- 779: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme</span>.<span class="ruby-identifier">nil?</span>
2093
- 780: <span class="ruby-keyword kw">end</span>
2094
- </pre>
2095
- </div>
2096
- </div>
2097
- </div>
2098
-
2099
- <div id="method-M000046" class="method-detail">
2100
- <a name="M000046"></a>
2101
-
2102
- <div class="method-heading">
2103
- <a href="#M000046" class="method-signature">
2104
- <span class="method-name">route_from</span><span class="method-args">(uri)</span>
2105
- </a>
2106
- </div>
2107
-
2108
- <div class="method-description">
2109
- <p>
2110
- Returns the shortest normalized relative form of this <a
2111
- href="URI.html">URI</a> that uses the supplied <a href="URI.html">URI</a>
2112
- as a base for resolution. Returns an absolute <a href="URI.html">URI</a> if
2113
- necessary.
2114
- </p>
2115
- <p><a class="source-toggle" href="#"
2116
- onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
2117
- <div class="method-source-code" id="M000046-source">
2118
- <pre>
2119
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 893</span>
2120
- 893: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">route_from</span>(<span class="ruby-identifier">uri</span>)
2121
- 894: <span class="ruby-identifier">uri</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">uri</span>).<span class="ruby-identifier">normalize</span>
2122
- 895: <span class="ruby-identifier">normalized_self</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">normalize</span>
2123
- 896: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">normalized_self</span>.<span class="ruby-identifier">relative?</span>
2124
- 897: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Expected absolute URI, got: #{self.to_s}&quot;</span>
2125
- 898: <span class="ruby-keyword kw">end</span>
2126
- 899: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">relative?</span>
2127
- 900: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Expected absolute URI, got: #{uri.to_s}&quot;</span>
2128
- 901: <span class="ruby-keyword kw">end</span>
2129
- 902: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">normalized_self</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">uri</span>
2130
- 903: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-node">&quot;##{normalized_self.fragment}&quot;</span>)
2131
- 904: <span class="ruby-keyword kw">end</span>
2132
- 905: <span class="ruby-identifier">segments</span> = <span class="ruby-identifier">normalized_self</span>.<span class="ruby-identifier">to_hash</span>
2133
- 906: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">normalized_self</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span>
2134
- 907: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:scheme</span>] = <span class="ruby-keyword kw">nil</span>
2135
- 908: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">normalized_self</span>.<span class="ruby-identifier">authority</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">authority</span>
2136
- 909: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:user</span>] = <span class="ruby-keyword kw">nil</span>
2137
- 910: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:password</span>] = <span class="ruby-keyword kw">nil</span>
2138
- 911: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:host</span>] = <span class="ruby-keyword kw">nil</span>
2139
- 912: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:port</span>] = <span class="ruby-keyword kw">nil</span>
2140
- 913: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">normalized_self</span>.<span class="ruby-identifier">path</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span>
2141
- 914: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:path</span>] = <span class="ruby-keyword kw">nil</span>
2142
- 915: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">normalized_self</span>.<span class="ruby-identifier">query</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">query</span>
2143
- 916: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:query</span>] = <span class="ruby-keyword kw">nil</span>
2144
- 917: <span class="ruby-keyword kw">end</span>
2145
- 918: <span class="ruby-keyword kw">else</span>
2146
- 919: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">&quot;/&quot;</span>
2147
- 920: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:path</span>].<span class="ruby-identifier">gsub!</span>(
2148
- 921: <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;^&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span>)), <span class="ruby-value str">&quot;&quot;</span>)
2149
- 922: <span class="ruby-keyword kw">end</span>
2150
- 923: <span class="ruby-keyword kw">end</span>
2151
- 924: <span class="ruby-keyword kw">end</span>
2152
- 925: <span class="ruby-keyword kw">end</span>
2153
- 926: <span class="ruby-comment cmt"># Avoid network-path references.</span>
2154
- 927: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:host</span>] <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
2155
- 928: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:scheme</span>] = <span class="ruby-identifier">normalized_self</span>.<span class="ruby-identifier">scheme</span>
2156
- 929: <span class="ruby-keyword kw">end</span>
2157
- 930: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span>.<span class="ruby-identifier">new</span>(
2158
- 931: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:scheme</span>],
2159
- 932: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:user</span>],
2160
- 933: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:password</span>],
2161
- 934: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:host</span>],
2162
- 935: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:port</span>],
2163
- 936: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:path</span>],
2164
- 937: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:query</span>],
2165
- 938: <span class="ruby-identifier">segments</span>[<span class="ruby-identifier">:fragment</span>]
2166
- 939: )
2167
- 940: <span class="ruby-keyword kw">end</span>
2168
- </pre>
2169
- </div>
2170
- </div>
2171
- </div>
2172
-
2173
- <div id="method-M000047" class="method-detail">
2174
- <a name="M000047"></a>
2175
-
2176
- <div class="method-heading">
2177
- <a href="#M000047" class="method-signature">
2178
- <span class="method-name">route_to</span><span class="method-args">(uri)</span>
2179
- </a>
2180
- </div>
2181
-
2182
- <div class="method-description">
2183
- <p>
2184
- Returns the shortest normalized relative form of the supplied <a
2185
- href="URI.html">URI</a> that uses this <a href="URI.html">URI</a> as a base
2186
- for resolution. Returns an absolute <a href="URI.html">URI</a> if
2187
- necessary.
2188
- </p>
2189
- <p><a class="source-toggle" href="#"
2190
- onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
2191
- <div class="method-source-code" id="M000047-source">
2192
- <pre>
2193
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 945</span>
2194
- 945: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">route_to</span>(<span class="ruby-identifier">uri</span>)
2195
- 946: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">uri</span>).<span class="ruby-identifier">route_from</span>(<span class="ruby-keyword kw">self</span>)
2196
- 947: <span class="ruby-keyword kw">end</span>
2197
- </pre>
2198
- </div>
2199
- </div>
2200
- </div>
2201
-
2202
- <div id="method-M000013" class="method-detail">
2203
- <a name="M000013"></a>
2204
-
2205
- <div class="method-heading">
2206
- <a href="#M000013" class="method-signature">
2207
- <span class="method-name">scheme</span><span class="method-args">()</span>
2208
- </a>
2209
- </div>
2210
-
2211
- <div class="method-description">
2212
- <p>
2213
- Returns the <a href="URI.html#M000013">scheme</a> (protocol) for this <a
2214
- href="URI.html">URI</a>.
2215
- </p>
2216
- <p><a class="source-toggle" href="#"
2217
- onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
2218
- <div class="method-source-code" id="M000013-source">
2219
- <pre>
2220
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 515</span>
2221
- 515: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">scheme</span>
2222
- 516: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@scheme</span>
2223
- 517: <span class="ruby-keyword kw">end</span>
2224
- </pre>
2225
- </div>
2226
- </div>
2227
- </div>
2228
-
2229
- <div id="method-M000014" class="method-detail">
2230
- <a name="M000014"></a>
2231
-
2232
- <div class="method-heading">
2233
- <a href="#M000014" class="method-signature">
2234
- <span class="method-name">scheme=</span><span class="method-args">(new_scheme)</span>
2235
- </a>
2236
- </div>
2237
-
2238
- <div class="method-description">
2239
- <p>
2240
- Sets the <a href="URI.html#M000013">scheme</a> (protocol for this <a
2241
- href="URI.html">URI</a>.)
2242
- </p>
2243
- <p><a class="source-toggle" href="#"
2244
- onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
2245
- <div class="method-source-code" id="M000014-source">
2246
- <pre>
2247
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 520</span>
2248
- 520: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">scheme=</span>(<span class="ruby-identifier">new_scheme</span>)
2249
- 521: <span class="ruby-ivar">@scheme</span> = <span class="ruby-identifier">new_scheme</span>
2250
- 522: <span class="ruby-keyword kw">end</span>
2251
- </pre>
2252
- </div>
2253
- </div>
2254
- </div>
2255
-
2256
- <div id="method-M000029" class="method-detail">
2257
- <a name="M000029"></a>
2258
-
2259
- <div class="method-heading">
2260
- <a href="#M000029" class="method-signature">
2261
- <span class="method-name">specified_port</span><span class="method-args">()</span>
2262
- </a>
2263
- </div>
2264
-
2265
- <div class="method-description">
2266
- <p>
2267
- Returns the <a href="URI.html#M000027">port</a> number that was actually
2268
- specified in the <a href="URI.html">URI</a> string.
2269
- </p>
2270
- <p><a class="source-toggle" href="#"
2271
- onclick="toggleCode('M000029-source');return false;">[Source]</a></p>
2272
- <div class="method-source-code" id="M000029-source">
2273
- <pre>
2274
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 714</span>
2275
- 714: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">specified_port</span>
2276
- 715: <span class="ruby-identifier">port</span> = <span class="ruby-ivar">@specified_port</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">to_i</span>
2277
- 716: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">port</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
2278
- 717: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
2279
- 718: <span class="ruby-keyword kw">else</span>
2280
- 719: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">port</span>
2281
- 720: <span class="ruby-keyword kw">end</span>
2282
- 721: <span class="ruby-keyword kw">end</span>
2283
- </pre>
2284
- </div>
2285
- </div>
2286
- </div>
2287
-
2288
- <div id="method-M000056" class="method-detail">
2289
- <a name="M000056"></a>
2290
-
2291
- <div class="method-heading">
2292
- <a href="#M000056" class="method-signature">
2293
- <span class="method-name">to_hash</span><span class="method-args">()</span>
2294
- </a>
2295
- </div>
2296
-
2297
- <div class="method-description">
2298
- <p>
2299
- Returns a Hash of the <a href="URI.html">URI</a> segments.
2300
- </p>
2301
- <p><a class="source-toggle" href="#"
2302
- onclick="toggleCode('M000056-source');return false;">[Source]</a></p>
2303
- <div class="method-source-code" id="M000056-source">
2304
- <pre>
2305
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1109</span>
2306
- 1109: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_hash</span>
2307
- 1110: <span class="ruby-keyword kw">return</span> {
2308
- 1111: <span class="ruby-identifier">:scheme</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme</span>,
2309
- 1112: <span class="ruby-identifier">:user</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">user</span>,
2310
- 1113: <span class="ruby-identifier">:password</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">password</span>,
2311
- 1114: <span class="ruby-identifier">:host</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">host</span>,
2312
- 1115: <span class="ruby-identifier">:port</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">specified_port</span>,
2313
- 1116: <span class="ruby-identifier">:path</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span>,
2314
- 1117: <span class="ruby-identifier">:query</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">query</span>,
2315
- 1118: <span class="ruby-identifier">:fragment</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">fragment</span>
2316
- 1119: }
2317
- 1120: <span class="ruby-keyword kw">end</span>
2318
- </pre>
2319
- </div>
2320
- </div>
2321
- </div>
2322
-
2323
- <div id="method-M000055" class="method-detail">
2324
- <a name="M000055"></a>
2325
-
2326
- <div class="method-heading">
2327
- <a href="#M000055" class="method-signature">
2328
- <span class="method-name">to_s</span><span class="method-args">()</span>
2329
- </a>
2330
- </div>
2331
-
2332
- <div class="method-description">
2333
- <p>
2334
- Returns the assembled <a href="URI.html">URI</a> as a string.
2335
- </p>
2336
- <p><a class="source-toggle" href="#"
2337
- onclick="toggleCode('M000055-source');return false;">[Source]</a></p>
2338
- <div class="method-source-code" id="M000055-source">
2339
- <pre>
2340
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1098</span>
2341
- 1098: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_s</span>
2342
- 1099: <span class="ruby-identifier">uri_string</span> = <span class="ruby-value str">&quot;&quot;</span>
2343
- 1100: <span class="ruby-identifier">uri_string</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{self.scheme}:&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
2344
- 1101: <span class="ruby-identifier">uri_string</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;//#{self.authority}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">authority</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
2345
- 1102: <span class="ruby-identifier">uri_string</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span>.<span class="ruby-identifier">to_s</span>
2346
- 1103: <span class="ruby-identifier">uri_string</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;?#{self.query}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">query</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
2347
- 1104: <span class="ruby-identifier">uri_string</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;##{self.fragment}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">fragment</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
2348
- 1105: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">uri_string</span>
2349
- 1106: <span class="ruby-keyword kw">end</span>
2350
- </pre>
2351
- </div>
2352
- </div>
2353
- </div>
2354
-
2355
- <div id="method-M000015" class="method-detail">
2356
- <a name="M000015"></a>
2357
-
2358
- <div class="method-heading">
2359
- <a href="#M000015" class="method-signature">
2360
- <span class="method-name">user</span><span class="method-args">()</span>
2361
- </a>
2362
- </div>
2363
-
2364
- <div class="method-description">
2365
- <p>
2366
- Returns the <a href="URI.html#M000015">user</a> for this <a
2367
- href="URI.html">URI</a>.
2368
- </p>
2369
- <p><a class="source-toggle" href="#"
2370
- onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
2371
- <div class="method-source-code" id="M000015-source">
2372
- <pre>
2373
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 525</span>
2374
- 525: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">user</span>
2375
- 526: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@user</span>
2376
- 527: <span class="ruby-keyword kw">end</span>
2377
- </pre>
2378
- </div>
2379
- </div>
2380
- </div>
2381
-
2382
- <div id="method-M000016" class="method-detail">
2383
- <a name="M000016"></a>
2384
-
2385
- <div class="method-heading">
2386
- <a href="#M000016" class="method-signature">
2387
- <span class="method-name">user=</span><span class="method-args">(new_user)</span>
2388
- </a>
2389
- </div>
2390
-
2391
- <div class="method-description">
2392
- <p>
2393
- Sets the <a href="URI.html#M000015">user</a> for this <a
2394
- href="URI.html">URI</a>.
2395
- </p>
2396
- <p><a class="source-toggle" href="#"
2397
- onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
2398
- <div class="method-source-code" id="M000016-source">
2399
- <pre>
2400
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 530</span>
2401
- 530: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">user=</span>(<span class="ruby-identifier">new_user</span>)
2402
- 531: <span class="ruby-ivar">@user</span> = <span class="ruby-identifier">new_user</span>
2403
- 532:
2404
- 533: <span class="ruby-comment cmt"># You can't have a nil user with a non-nil password</span>
2405
- 534: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@password</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
2406
- 535: <span class="ruby-ivar">@user</span> = <span class="ruby-value str">&quot;&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@user</span>.<span class="ruby-identifier">nil?</span>
2407
- 536: <span class="ruby-keyword kw">end</span>
2408
- 537:
2409
- 538: <span class="ruby-comment cmt"># Reset dependant values</span>
2410
- 539: <span class="ruby-ivar">@userinfo</span> = <span class="ruby-keyword kw">nil</span>
2411
- 540: <span class="ruby-ivar">@authority</span> = <span class="ruby-keyword kw">nil</span>
2412
- 541:
2413
- 542: <span class="ruby-comment cmt"># Ensure we haven't created an invalid URI</span>
2414
- 543: <span class="ruby-identifier">validate</span>()
2415
- 544: <span class="ruby-keyword kw">end</span>
2416
- </pre>
2417
- </div>
2418
- </div>
2419
- </div>
2420
-
2421
- <div id="method-M000019" class="method-detail">
2422
- <a name="M000019"></a>
2423
-
2424
- <div class="method-heading">
2425
- <a href="#M000019" class="method-signature">
2426
- <span class="method-name">userinfo</span><span class="method-args">()</span>
2427
- </a>
2428
- </div>
2429
-
2430
- <div class="method-description">
2431
- <p>
2432
- Returns the username and <a href="URI.html#M000017">password</a> segment of
2433
- this <a href="URI.html">URI</a>.
2434
- </p>
2435
- <p><a class="source-toggle" href="#"
2436
- onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
2437
- <div class="method-source-code" id="M000019-source">
2438
- <pre>
2439
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 569</span>
2440
- 569: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">userinfo</span>
2441
- 570: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-keyword kw">defined?</span>(<span class="ruby-ivar">@userinfo</span>) <span class="ruby-operator">||</span> <span class="ruby-ivar">@userinfo</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span>
2442
- 571: <span class="ruby-identifier">current_user</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">user</span>
2443
- 572: <span class="ruby-identifier">current_password</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">password</span>
2444
- 573: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">current_user</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">current_password</span>
2445
- 574: <span class="ruby-ivar">@userinfo</span> = <span class="ruby-keyword kw">nil</span>
2446
- 575: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">current_user</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">current_password</span>
2447
- 576: <span class="ruby-ivar">@userinfo</span> = <span class="ruby-node">&quot;#{current_user}:#{current_password}&quot;</span>
2448
- 577: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">current_user</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">current_password</span>
2449
- 578: <span class="ruby-ivar">@userinfo</span> = <span class="ruby-node">&quot;#{current_user}&quot;</span>
2450
- 579: <span class="ruby-keyword kw">end</span>
2451
- 580: <span class="ruby-keyword kw">end</span>
2452
- 581: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@userinfo</span>
2453
- 582: <span class="ruby-keyword kw">end</span>
2454
- </pre>
2455
- </div>
2456
- </div>
2457
- </div>
2458
-
2459
- <div id="method-M000020" class="method-detail">
2460
- <a name="M000020"></a>
2461
-
2462
- <div class="method-heading">
2463
- <a href="#M000020" class="method-signature">
2464
- <span class="method-name">userinfo=</span><span class="method-args">(new_userinfo)</span>
2465
- </a>
2466
- </div>
2467
-
2468
- <div class="method-description">
2469
- <p>
2470
- Sets the username and <a href="URI.html#M000017">password</a> segment of
2471
- this <a href="URI.html">URI</a>.
2472
- </p>
2473
- <p><a class="source-toggle" href="#"
2474
- onclick="toggleCode('M000020-source');return false;">[Source]</a></p>
2475
- <div class="method-source-code" id="M000020-source">
2476
- <pre>
2477
- <span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 585</span>
2478
- 585: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">userinfo=</span>(<span class="ruby-identifier">new_userinfo</span>)
2479
- 586: <span class="ruby-identifier">new_user</span> = <span class="ruby-identifier">new_userinfo</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/^(.*):/</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]
2480
- 587: <span class="ruby-identifier">new_password</span> = <span class="ruby-identifier">new_userinfo</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/:(.*)$/</span>).<span class="ruby-identifier">flatten</span>[<span class="ruby-value">0</span>]
2481
- 588:
2482
- 589: <span class="ruby-comment cmt"># Password assigned first to ensure validity in case of nil</span>
2483
- 590: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">password</span> = <span class="ruby-identifier">new_password</span>
2484
- 591: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">user</span> = <span class="ruby-identifier">new_user</span>
2485
- 592:
2486
- 593: <span class="ruby-comment cmt"># Reset dependant values</span>
2487
- 594: <span class="ruby-ivar">@authority</span> = <span class="ruby-keyword kw">nil</span>
2488
- 595:
2489
- 596: <span class="ruby-comment cmt"># Ensure we haven't created an invalid URI</span>
2490
- 597: <span class="ruby-identifier">validate</span>()
2491
- 598: <span class="ruby-keyword kw">end</span>
2492
- </pre>
2493
- </div>
2494
- </div>
2495
- </div>
2496
-
2497
-
2498
- </div>
2499
-
2500
-
2501
- </div>
2502
-
2503
-
2504
- <div id="validator-badges">
2505
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
2506
- </div>
2507
-
2508
- </body>
2509
- </html>