furi 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/furi.rb +58 -47
- data/lib/furi/version.rb +1 -1
- data/spec/furi_spec.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 208063d16947ce85a4d80a12bd3834cb26c0f6ab
|
4
|
+
data.tar.gz: ab3eff6b787f0df3e04781908477bb69d3924333
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 500c3e4bb3ed0866c0cef1ca68794d9d82e9d2b679bb1590f69e14428bb1020a64d5c357c166e25b0c522902b670e5138269e649f395455f48acc4bca50785eb
|
7
|
+
data.tar.gz: bae87908fe1a04c26d1073d569199adda1645bc25f561ec0aa9b2e05943e55d0993223c3d329335c07afcac8c814e87c2a738573a2837be2996cb38339e3078f
|
data/lib/furi.rb
CHANGED
@@ -42,8 +42,12 @@ module Furi
|
|
42
42
|
Expressions.new
|
43
43
|
end
|
44
44
|
|
45
|
-
def self.parse(
|
46
|
-
Uri.new(
|
45
|
+
def self.parse(argument)
|
46
|
+
Uri.new(argument)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.build(argument)
|
50
|
+
Uri.new(argument).to_s
|
47
51
|
end
|
48
52
|
|
49
53
|
class << self
|
@@ -201,26 +205,20 @@ module Furi
|
|
201
205
|
define_method(aliaz) do
|
202
206
|
send(origin)
|
203
207
|
end
|
204
|
-
end
|
205
|
-
end
|
206
208
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
if string.include?("?")
|
211
|
-
string, query_string = string.split("?", 2)
|
212
|
-
@query_string = query_string
|
209
|
+
define_method(:"#{aliaz}=") do |*args|
|
210
|
+
send(:"#{origin}=", *args)
|
211
|
+
end
|
213
212
|
end
|
213
|
+
end
|
214
214
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
string = string[2..-1]
|
215
|
+
def initialize(argument)
|
216
|
+
case argument
|
217
|
+
when String
|
218
|
+
parse_uri_string(argument)
|
219
|
+
when Hash
|
220
|
+
update(argument)
|
222
221
|
end
|
223
|
-
parse_authority(string)
|
224
222
|
end
|
225
223
|
|
226
224
|
def update(parts)
|
@@ -256,6 +254,15 @@ module Furi
|
|
256
254
|
end
|
257
255
|
end
|
258
256
|
|
257
|
+
def host=(string)
|
258
|
+
@port = nil
|
259
|
+
if string.include?(":")
|
260
|
+
string, @port = string.split(":", 2)
|
261
|
+
@port = @port.to_i
|
262
|
+
end
|
263
|
+
@hostname = string.empty? ? nil : string
|
264
|
+
end
|
265
|
+
|
259
266
|
def to_s
|
260
267
|
result = []
|
261
268
|
if protocol
|
@@ -275,27 +282,6 @@ module Furi
|
|
275
282
|
result.join
|
276
283
|
end
|
277
284
|
|
278
|
-
def parse_authority(string)
|
279
|
-
if string.include?("/")
|
280
|
-
string, @path = string.split("/", 2)
|
281
|
-
@path = "/" + @path
|
282
|
-
end
|
283
|
-
|
284
|
-
if string.include?("@")
|
285
|
-
userinfo, string = string.split("@", 2)
|
286
|
-
@username, @password = userinfo.split(":", 2)
|
287
|
-
end
|
288
|
-
if string.include?(":")
|
289
|
-
string, @port = string.split(":", 2)
|
290
|
-
@port = @port.to_i
|
291
|
-
end
|
292
|
-
if string.empty?
|
293
|
-
@hostname = nil
|
294
|
-
else
|
295
|
-
@hostname = string
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
285
|
def query
|
300
286
|
return @query if query_level?
|
301
287
|
@query = Furi.parse_nested_query(@query_string)
|
@@ -358,23 +344,48 @@ module Furi
|
|
358
344
|
protocol ? PORT_MAPPING[protocol] : nil
|
359
345
|
end
|
360
346
|
|
361
|
-
|
362
|
-
default_port && (!port || port == default_port)
|
363
|
-
end
|
347
|
+
protected
|
364
348
|
|
365
|
-
def
|
366
|
-
|
349
|
+
def query_level?
|
350
|
+
!!@query
|
367
351
|
end
|
368
352
|
|
369
353
|
def explicit_port
|
370
354
|
port == default_port ? nil : port
|
371
355
|
end
|
372
356
|
|
373
|
-
|
357
|
+
def parse_uri_string(string)
|
358
|
+
string, *@anchor = string.split("#")
|
359
|
+
@anchor = @anchor.empty? ? nil : @anchor.join("#")
|
360
|
+
if string.include?("?")
|
361
|
+
string, query_string = string.split("?", 2)
|
362
|
+
@query_string = query_string
|
363
|
+
end
|
374
364
|
|
375
|
-
|
376
|
-
|
365
|
+
if string.include?("://")
|
366
|
+
@protocol, string = string.split(":", 2)
|
367
|
+
@protocol = '' if @protocol.empty?
|
368
|
+
end
|
369
|
+
if string.start_with?("//")
|
370
|
+
@protocol ||= ''
|
371
|
+
string = string[2..-1]
|
372
|
+
end
|
373
|
+
parse_authority(string)
|
374
|
+
end
|
375
|
+
|
376
|
+
def parse_authority(string)
|
377
|
+
if string.include?("/")
|
378
|
+
string, @path = string.split("/", 2)
|
379
|
+
@path = "/" + @path
|
380
|
+
end
|
381
|
+
|
382
|
+
if string.include?("@")
|
383
|
+
userinfo, string = string.split("@", 2)
|
384
|
+
@username, @password = userinfo.split(":", 2)
|
385
|
+
end
|
386
|
+
self.host = string
|
377
387
|
end
|
388
|
+
|
378
389
|
end
|
379
390
|
|
380
391
|
class FormattingError < StandardError
|
data/lib/furi/version.rb
CHANGED
data/spec/furi_spec.rb
CHANGED
@@ -180,6 +180,16 @@ describe Furi do
|
|
180
180
|
|
181
181
|
end
|
182
182
|
|
183
|
+
describe ".build" do
|
184
|
+
it "should work correctly" do
|
185
|
+
expect(Furi.build(hostname: 'hello.com')).to eq('hello.com')
|
186
|
+
expect(Furi.build(hostname: 'hello.com', port: 88)).to eq('hello.com:88')
|
187
|
+
expect(Furi.build(hostname: 'hello.com', port: 88)).to eq('hello.com:88')
|
188
|
+
expect(Furi.build(schema: 'https', hostname: 'hello.com', port: 88)).to eq('https://hello.com:88')
|
189
|
+
expect(Furi.build(schema: 'http', hostname: 'hello.com', port: 80)).to eq('http://hello.com')
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
183
193
|
|
184
194
|
describe "serialize" do
|
185
195
|
it "should work" do
|