qasa-url 0.1.0 → 0.1.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/qasa/url/version.rb +1 -1
- data/lib/url.rb +26 -7
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70e637380f87112da94c4baabe3f72d117175fcf151978501057034cddee03bd
|
4
|
+
data.tar.gz: e93986b23ed44518830a92af7ce6c7da5c7c096bf4a0f3de30b70dbf696e79d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edfaad59c0df751e0b3da3420322d5d9b7be56bb0cc68b095b58fd22ade71af2ce0edfe34c351412d2ccaf640535de5bcb2c0036413c05bb8979384f438cd876
|
7
|
+
data.tar.gz: b5b65f227aad9869a2c7430a90b52743b54c06ff9aeb73ad60aa2043ede1b9c4155655c8b6f6684802387fb16c919256cac4439b4f3666d3f0bc298413713190
|
data/lib/qasa/url/version.rb
CHANGED
data/lib/url.rb
CHANGED
@@ -12,6 +12,7 @@ class URL
|
|
12
12
|
PORT_SEPARATOR = ":"
|
13
13
|
QUERY_STRING_SEPARATOR = "?"
|
14
14
|
SEPARATOR = "://"
|
15
|
+
PROTOCOL_MATCHER = /\A[a-z0-9.+-]*#{Regexp.escape(SEPARATOR)}/io
|
15
16
|
SLASH = "/"
|
16
17
|
SPACE = " "
|
17
18
|
|
@@ -59,6 +60,8 @@ class URL
|
|
59
60
|
# URL.parse("https://www.example.com:3000/path?query=string")
|
60
61
|
# # => #<URL:0x00007f9b9c0b3b20 https://www.example.com:3000/path?query=string>
|
61
62
|
def parse(string)
|
63
|
+
return nil if string.nil?
|
64
|
+
|
62
65
|
string
|
63
66
|
.to_str
|
64
67
|
.dup
|
@@ -80,8 +83,8 @@ class URL
|
|
80
83
|
private
|
81
84
|
|
82
85
|
def extract_protocol(string)
|
83
|
-
if string.
|
84
|
-
string.split(SEPARATOR)
|
86
|
+
if string.match?(PROTOCOL_MATCHER)
|
87
|
+
string.split(SEPARATOR, 2)
|
85
88
|
else
|
86
89
|
[nil, string]
|
87
90
|
end
|
@@ -141,12 +144,21 @@ class URL
|
|
141
144
|
# url = URL.parse("https://www.example.com")
|
142
145
|
# url.join("path").path("to", "nowhere")
|
143
146
|
# url.to_s # => "https://www.example.com/path/to/nowhere"
|
147
|
+
# @example
|
148
|
+
# url = URL.parse("https://www.example.com/")
|
149
|
+
# url.join("/path", "/to/", "nowhere/")
|
150
|
+
# url.to_s # => "https://www.example.com/path/to/nowhere/"
|
144
151
|
def join(*paths)
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
152
|
+
parts = Array(path).concat(paths)
|
153
|
+
size = parts.size
|
154
|
+
|
155
|
+
parts
|
156
|
+
.map
|
157
|
+
.with_index(1) { |part, index| sanitize_path(part, last: index == size) }
|
158
|
+
.compact
|
159
|
+
.then do |parts|
|
160
|
+
self.path = Array(NOTHING).concat(parts).join(SLASH)
|
161
|
+
end
|
150
162
|
|
151
163
|
self
|
152
164
|
end
|
@@ -293,4 +305,11 @@ class URL
|
|
293
305
|
def domain_parts
|
294
306
|
host.split(DOT)
|
295
307
|
end
|
308
|
+
|
309
|
+
def sanitize_path(path, last:)
|
310
|
+
path = path.start_with?(SLASH) ? path[1..] : path.dup
|
311
|
+
path = path.end_with?(SLASH) ? path[..-2] : path unless last
|
312
|
+
|
313
|
+
path.empty? ? nil : path
|
314
|
+
end
|
296
315
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qasa-url
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ingemar
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rack
|
@@ -53,7 +52,6 @@ metadata:
|
|
53
52
|
homepage_uri: https://github.com/qasase/qasa-url
|
54
53
|
source_code_uri: https://github.com/qasase/qasa-url
|
55
54
|
changelog_uri: https://github.com/qasase/qasa-url/blob/main/CHANGELOG.md
|
56
|
-
post_install_message:
|
57
55
|
rdoc_options: []
|
58
56
|
require_paths:
|
59
57
|
- lib
|
@@ -68,8 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
66
|
- !ruby/object:Gem::Version
|
69
67
|
version: '0'
|
70
68
|
requirements: []
|
71
|
-
rubygems_version: 3.
|
72
|
-
signing_key:
|
69
|
+
rubygems_version: 3.6.9
|
73
70
|
specification_version: 4
|
74
71
|
summary: A simple URL parser and construction tool
|
75
72
|
test_files: []
|