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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/qasa/url/version.rb +1 -1
  3. data/lib/url.rb +23 -5
  4. metadata +3 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15c6031d5e90337cc47cfdd900ff9a6329b9e1da4b1233292383a9cc5fbe60b1
4
- data.tar.gz: dfcf70b764fd7b28a3c1411cb8229cb588d788c266b3881118366602cbd63bd5
3
+ metadata.gz: 67347532971523184f8c7744c77f9b8ab3c9b6c749a41903691fd166b84198a9
4
+ data.tar.gz: c8f386a8835ef38ea0e66806e956b539eb44c2bec4f74d381e872f44d542cda0
5
5
  SHA512:
6
- metadata.gz: 213ea1a16224606b1372b1f15bf5653f0951e977bc18f844f57b0f3b94c79de95c6d66decceda0c7ddc5a9c5a4e94fa8b0ae6042fcfabc5dc26ba25006f043ca
7
- data.tar.gz: df2d08fa816ca7ee3eb0a7ea5f9260541e99a786c64f29d8c38cf94cecc06ebcb1256e14dfc1977fb3d8ea3a7c3b4951741f26abe11ee8e04af6fd57d0e48aa8
6
+ metadata.gz: 29655dd7b541268fc327429989104d0b41caf657d9eaf8d83264c467761dbedf06a76b60cfdb936cd91b8a577cbe5331c629a3a9575e1f4281cd63cf06bd9360
7
+ data.tar.gz: 299acc459c9ca12b1942f5d0627c719c2e5a66d5cdf914ae3db471be59872dd809ea8d54c671ac7131b1d03fedd569ff8a343f642fe231859550c531e2d5b4b9
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Qasa
4
4
  module Url
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
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
- paths.map do |path|
146
- path.start_with?(SLASH) ? path.sub(SLASH, NOTHING) : path.dup
147
- end.then do |paths|
148
- self.path = Array(path).concat(paths).join(SLASH)
149
- end
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.0
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: 2023-12-25 00:00:00.000000000 Z
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.5.2
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: []