philiprehberger-json_path 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: a5f622166e4beba5e485f24b63a4286e28b6745c120a1271cd3e663cfe87150f
4
- data.tar.gz: 71dd674e321a36c295037a9672ab8c92f0eb87e6709a9ec7bbc98299abc14343
3
+ metadata.gz: 9d1f6e3df479eeb12b69af816742069bd38c31953c3b1611add83bc3aac4434a
4
+ data.tar.gz: 69b8a9a12b7a95fcf12ac173c6559d9e002a9d8d085c05b28716eb9948262fe5
5
5
  SHA512:
6
- metadata.gz: ff4e5a102c7c9ab0d59add298fbd4b9b2d4f9feb2d88274cdebdbb7358cdcb97aeccd99c62e6d5e38990902a1840224e4c042cb3e03c5751cb21a27f14a95410
7
- data.tar.gz: 1bb735639d90eb6827d01b6b5a37ad5b9c63d9dcece71dfd45ef124bae7cca27de0dab19335184e0351e3f86c1905603f2f39aa8b48325183542dfa60adac16e
6
+ metadata.gz: c603bf6cd3c2a58f248b1ca535ebcd63d28f3d1cdc269ff73f7e2889f161316c0a1c3a710c7e250c5529d090458fc42ffeac1cb2a43020fb81d037b500548a04
7
+ data.tar.gz: 12a21c296a86fe78d87ffd71ad9bba9b81200d60c8ffb1f3959e77f56f7312d31fda4d04fc00e3baa37103dee548237d0827810d8abe672b148b696d86f9c9e4
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ 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-19
11
+
12
+ ### Added
13
+ - `JsonPath.last(data, path)` — last matching value; symmetric with existing `.first`; returns `nil` on no match
14
+
10
15
  ## [0.3.0] - 2026-04-17
11
16
 
12
17
  ### Added
data/README.md CHANGED
@@ -48,6 +48,10 @@ Philiprehberger::JsonPath.values(data, '$.store.books[*].title')
48
48
  Philiprehberger::JsonPath.first(data, '$.store.books[0].title')
49
49
  # => "Ruby"
50
50
 
51
+ items = { "items" => [{ "id" => 1 }, { "id" => 2 }, { "id" => 3 }] }
52
+ Philiprehberger::JsonPath.first(items, "$.items[*].id") # => 1
53
+ Philiprehberger::JsonPath.last(items, "$.items[*].id") # => 3
54
+
51
55
  Philiprehberger::JsonPath.count(data, '$.store.books[*]')
52
56
  # => 3
53
57
 
@@ -149,6 +153,7 @@ Philiprehberger::JsonPath.query(data, '$.groups[?(@.members.length > 0)].name')
149
153
  | `JsonPath.query(data, path)` | Return all matches as an array |
150
154
  | `JsonPath.values(data, path)` | Alias for `query` |
151
155
  | `JsonPath.first(data, path)` | Return the first match or nil |
156
+ | `JsonPath.last(data, path)` | Return the last match or nil |
152
157
  | `JsonPath.count(data, path)` | Return the number of matches |
153
158
  | `JsonPath.exists?(data, path)` | Check if any match exists |
154
159
  | `JsonPath.paths(data, path)` | Return canonical JSONPath strings for each match |
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module JsonPath
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -34,6 +34,15 @@ module Philiprehberger
34
34
  query(data, path).first
35
35
  end
36
36
 
37
+ # Query data and return the last match
38
+ #
39
+ # @param data [Hash, Array] the data structure to query
40
+ # @param path [String] JSONPath expression
41
+ # @return [Object, nil] the last matching value or nil
42
+ def self.last(data, path)
43
+ query(data, path).last
44
+ end
45
+
37
46
  # Return the number of matches for a JSONPath expression
38
47
  #
39
48
  # @param data [Hash, Array] the data structure to query
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-json_path
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
  - philiprehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-18 00:00:00.000000000 Z
11
+ date: 2026-04-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Evaluate JSONPath expressions against Ruby hashes and arrays. Supports
14
14
  dot notation, array indexing, wildcards, slices, filter expressions, recursive descent,