qasa-url 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/qasa/url/version.rb +1 -1
- data/lib/url.rb +23 -5
- 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: 67347532971523184f8c7744c77f9b8ab3c9b6c749a41903691fd166b84198a9
|
4
|
+
data.tar.gz: c8f386a8835ef38ea0e66806e956b539eb44c2bec4f74d381e872f44d542cda0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29655dd7b541268fc327429989104d0b41caf657d9eaf8d83264c467761dbedf06a76b60cfdb936cd91b8a577cbe5331c629a3a9575e1f4281cd63cf06bd9360
|
7
|
+
data.tar.gz: 299acc459c9ca12b1942f5d0627c719c2e5a66d5cdf914ae3db471be59872dd809ea8d54c671ac7131b1d03fedd569ff8a343f642fe231859550c531e2d5b4b9
|
data/lib/qasa/url/version.rb
CHANGED
data/lib/url.rb
CHANGED
@@ -59,6 +59,8 @@ class URL
|
|
59
59
|
# URL.parse("https://www.example.com:3000/path?query=string")
|
60
60
|
# # => #<URL:0x00007f9b9c0b3b20 https://www.example.com:3000/path?query=string>
|
61
61
|
def parse(string)
|
62
|
+
return nil if string.nil?
|
63
|
+
|
62
64
|
string
|
63
65
|
.to_str
|
64
66
|
.dup
|
@@ -141,12 +143,21 @@ class URL
|
|
141
143
|
# url = URL.parse("https://www.example.com")
|
142
144
|
# url.join("path").path("to", "nowhere")
|
143
145
|
# url.to_s # => "https://www.example.com/path/to/nowhere"
|
146
|
+
# @example
|
147
|
+
# url = URL.parse("https://www.example.com/")
|
148
|
+
# url.join("/path", "/to/", "nowhere/")
|
149
|
+
# url.to_s # => "https://www.example.com/path/to/nowhere/"
|
144
150
|
def join(*paths)
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
151
|
+
parts = Array(path).concat(paths)
|
152
|
+
size = parts.size
|
153
|
+
|
154
|
+
parts
|
155
|
+
.map
|
156
|
+
.with_index(1) { |part, index| sanitize_path(part, last: index == size) }
|
157
|
+
.compact
|
158
|
+
.then do |parts|
|
159
|
+
self.path = Array(NOTHING).concat(parts).join(SLASH)
|
160
|
+
end
|
150
161
|
|
151
162
|
self
|
152
163
|
end
|
@@ -293,4 +304,11 @@ class URL
|
|
293
304
|
def domain_parts
|
294
305
|
host.split(DOT)
|
295
306
|
end
|
307
|
+
|
308
|
+
def sanitize_path(path, last:)
|
309
|
+
path = path.start_with?(SLASH) ? path[1..] : path.dup
|
310
|
+
path = path.end_with?(SLASH) ? path[..-2] : path unless last
|
311
|
+
|
312
|
+
path.empty? ? nil : path
|
313
|
+
end
|
296
314
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ingemar
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-11 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.3
|
73
70
|
specification_version: 4
|
74
71
|
summary: A simple URL parser and construction tool
|
75
72
|
test_files: []
|