philiprehberger-uri_kit 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a026f3d20cd016c911d1a4218e7eae2a8f636a54548ca0b226cb9306d20161fd
4
- data.tar.gz: 557e3f6ff76a3c92c9346f67f0d3c9d44b083a07ca768bea060c4fa31d2966ff
3
+ metadata.gz: 6805b914ee5a6a261855d040fb9709751d291785b84e1b3cac359aa15b970b60
4
+ data.tar.gz: dbd6208984bcae93f03fb402e9a0c2afafc2d2ccb6ce1ca80bd23c33c8d281c1
5
5
  SHA512:
6
- metadata.gz: 6f97d4a9d71f30dd31520affc81b20d49927c17068ab6ac58149e018c1cc2db7f49dbe02c05906c03364c3e8d924f9a95068f23ae6b6a8879b8b10c5dbd6952d
7
- data.tar.gz: 5415549cb15e13d66785af54af0c4c5664e7fbbd7ce1bae50399e54af5dd644d3e9d6f8fc7db4b36255b386f73d4d9ea92b97cd3444e2af817ecd5322e360fd8
6
+ metadata.gz: 539b261b7251b4228f9015f307744b151f4b34c826a2678f78bddc9c94bfedee38c382fced41b0f8f9e0a35fcab6cb55a90465b3e659735acd0e721e1bf200f8
7
+ data.tar.gz: 8667c1db624c568cb0a2cdd03b0f46f723ff4d0168309e90fa3da6564b316a563a74ce4c15775ab6772147e49d8582cb3fbb4a586ab153dada798f43c41fba91
data/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.0] - 2026-04-20
11
+
12
+ ### Added
13
+ - `Url#keep_params(*keys)` — return a new `Url` containing only the listed query parameters, dropping every other key. Accepts individual `String`/`Symbol` keys or a single array argument; calling with no keys drops the whole query.
14
+
15
+ ## [0.3.1] - 2026-04-15
16
+
17
+ ### Changed
18
+ - Update homepage metadata URL to use hyphenated package slug
19
+
10
20
  ## [0.3.0] - 2026-04-09
11
21
 
12
22
  ### Added
data/README.md CHANGED
@@ -87,6 +87,9 @@ with_params.to_s # => "https://example.com/search?q=ruby&page=1&limit=10"
87
87
 
88
88
  cleared = url.clear_params
89
89
  cleared.to_s # => "https://example.com/search"
90
+
91
+ tracking = Philiprehberger::UriKit.parse('https://example.com/p?utm_source=x&id=42')
92
+ tracking.keep_params('id').to_s # => "https://example.com/p?id=42"
90
93
  ```
91
94
 
92
95
  ### Base URL
@@ -144,6 +147,7 @@ url.to_s # => "https://example.com/base/page.html"
144
147
  | `Url#replace_path(new_path)` | Replace the entire path, returns new Url |
145
148
  | `Url#add_params(hash)` | Add multiple query parameters, returns new Url |
146
149
  | `Url#clear_params` | Remove all query parameters, returns new Url |
150
+ | `Url#keep_params(*keys)` | Keep only the listed query params, drop the rest; returns new Url |
147
151
  | `Url#base_url` | Get scheme + host + port as a string |
148
152
  | `Url#scheme` | URL scheme (e.g. `"https"`) |
149
153
  | `Url#host` | Hostname |
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module UriKit
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -133,6 +133,20 @@ module Philiprehberger
133
133
  build_with(query: nil)
134
134
  end
135
135
 
136
+ # Keep only the query parameters matching the given keys. Returns a new
137
+ # Url with every other parameter dropped. Accepts String or Symbol keys;
138
+ # comparison is performed against the decoded parameter names.
139
+ #
140
+ # @param keys [Array<String, Symbol>] parameter keys to retain
141
+ # @return [Url] a new Url containing at most the listed parameters
142
+ def keep_params(*keys)
143
+ allow = keys.flatten.map(&:to_s)
144
+ filtered = params.slice(*allow)
145
+ new_url = build_with(query: nil)
146
+ new_url.instance_variable_get(:@uri).query = encode_params(filtered) unless filtered.empty?
147
+ new_url
148
+ end
149
+
136
150
  # Get the base URL (scheme + host + port only)
137
151
  #
138
152
  # @return [String] the base URL string
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-uri_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-10 00:00:00.000000000 Z
11
+ date: 2026-04-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Parse, build, and manipulate URLs with query parameter management, normalization,
14
14
  domain extraction, and URL joining. Built on Ruby stdlib URI.