philiprehberger-csv_kit 0.5.0 → 0.6.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: 63dcb3883c3732b41c45224ad90e4ae26ea4af2efced584db70089e0b5802be9
4
- data.tar.gz: 672c6414f9620772b8cbb664b6cfdbc7a37f76b38d2456cdf72e83d947bca659
3
+ metadata.gz: 7a49695d1e89645d30e0d325f7c7967db04b044f0cfe69ecf66cabfcc7e28470
4
+ data.tar.gz: 8a0cd35cd652e1893493ac4a0428251517c4a234cc0dca7b1addc9580b3688c6
5
5
  SHA512:
6
- metadata.gz: ca664b0389948c7a12793a238f3b94189ef8bc7bbed4aeecdbb431cc986dfad0386f1e621922ba655bdfe85605ba9f2abcdd11550758604d5dad052e6b42d26e
7
- data.tar.gz: 973ccc2da16d11249c0dc4c1f1826a42815503b6800bfa9def603f8884dc041e23c37c81ddd9f1fcd719df58438c445a815add96e4de214513f4b6e01f0679c3
6
+ metadata.gz: 528761ab2269e586d1d01c20885b5113dd12fe89b94b266b4bcb7452224cedd19a626100218d77def4db8b4d087117717dd3a6738aa5fe54c4c05f20b7592b5c
7
+ data.tar.gz: 2838f1cb2c0bb9caa43015b2f8f07e3b6252f80d4ad376160619d2c3dc50c4f1fecb65d6d5c47f9e86ffa2537e6b9ace01623a266aa2bc9cfd0fd4c0e9977512
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.6.0] - 2026-04-15
11
+
12
+ ### Added
13
+ - `CsvKit.find(path, &block)` — return the first row matching a predicate, stopping as soon as a match is found
14
+
10
15
  ## [0.5.0] - 2026-04-09
11
16
 
12
17
  ### Added
data/README.md CHANGED
@@ -69,6 +69,15 @@ adults = Philiprehberger::CsvKit.each_hash("data.csv")
69
69
  .first(10)
70
70
  ```
71
71
 
72
+ ### Find First Match
73
+
74
+ Return the first row that matches a predicate, streaming and stopping on the first hit:
75
+
76
+ ```ruby
77
+ user = Philiprehberger::CsvKit.find("users.csv") { |row| row[:email] == "a@b.com" }
78
+ # => {email: "a@b.com", name: "Alice"} or nil
79
+ ```
80
+
72
81
  ### Filter Rows
73
82
 
74
83
  ```ruby
@@ -168,6 +177,7 @@ delimiter = Philiprehberger::CsvKit::Detector.detect("data.tsv")
168
177
  | `CsvKit.to_hashes(path, dialect:)` | Load CSV into array of symbolized hashes |
169
178
  | `CsvKit.pluck(path, *keys, dialect:)` | Extract specific columns |
170
179
  | `CsvKit.filter(path, dialect:, &block)` | Filter rows, return CSV string |
180
+ | `CsvKit.find(path, dialect:, &block)` | Return the first row matching the predicate, or nil |
171
181
  | `CsvKit.headers(path, dialect:)` | Return header row as array of symbols |
172
182
  | `CsvKit.count(path, dialect:)` | Count data rows without loading into memory |
173
183
  | `CsvKit.each_hash(path, dialect:, &block)` | Stream rows as symbolized hashes; returns Enumerator if no block |
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module CsvKit
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
@@ -100,6 +100,22 @@ module Philiprehberger
100
100
  block ? enum.each(&block) : enum
101
101
  end
102
102
 
103
+ # Find the first row matching a predicate, streaming (stops as soon as a match is found).
104
+ #
105
+ # @param path [String] file path
106
+ # @param dialect [Symbol, Hash, nil] CSV dialect preset or custom options
107
+ # @yield [Hash{Symbol => String}] each row as a symbolized hash
108
+ # @return [Hash{Symbol => String}, nil] the first matching row or nil
109
+ def self.find(path, dialect: nil, &block)
110
+ csv_opts = { headers: true }
111
+ csv_opts = Dialect.new(dialect).merge_into(csv_opts) if dialect
112
+ CSV.foreach(path, **csv_opts) do |row|
113
+ hash = row.to_h.transform_keys(&:to_sym)
114
+ return hash if block.call(hash)
115
+ end
116
+ nil
117
+ end
118
+
103
119
  # Filter rows and return matching rows as a CSV string.
104
120
  #
105
121
  # @param path [String] file path
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-csv_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.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-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Streaming CSV processor with row-by-row transforms, validations, column
14
14
  plucking, streaming each_hash iteration, filtering, writing, error recovery, and