philiprehberger-csv_kit 0.9.0 → 0.10.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: 85d915adb35a580821d1055d966fe76b802598d6422571ad1e727694dd604a4f
4
- data.tar.gz: 66cc520a86bae535668b77aa56ae7d154ddc1f5df22cca7b4578d4b12a7958e8
3
+ metadata.gz: 2ad7f9f8f543aa7336129a60b131b397f7d46884dc63949aed97ffcdeea41a99
4
+ data.tar.gz: 623d9169efd50e7f1bf3894c7a6b7ffbc99c79085a444d633c280af727f0f8b6
5
5
  SHA512:
6
- metadata.gz: 0b719464ccea551cb56975fe78985ffa2f49480f2439e9a528f091afa53b5b24dd55219dbab3e65a8f30ec1f326959749ad4162e52d36471b1ee3bfd1272afcd
7
- data.tar.gz: 7f98968c2c5063109053f2a4a8f4508f6544e5238f783440969f237f593b66f4ac2a2ace4e6b495862621944fe891c44107a247366d3c1cedd59be6208a88df9
6
+ metadata.gz: aaee8ffddffaabf495a59a9e5b7b00d2ebfbcc73f06d73229f96c11184f16c7215203ead52e77c1bc109e29d8eb28e2b2b5e728c64d094bb35af953a5c62aad7
7
+ data.tar.gz: a310d1904161f42549cff7b2dfee711d2f483e6b2cb9ff5428267e9118bdc80130af7b701b47ad6e659c56dddb29607f7b6d5eea0af6dd0e667b207e0fc2e765
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.10.0] - 2026-05-07
11
+
12
+ ### Added
13
+ - `CsvKit.transpose(path_or_io, dialect:)` — returns a column-oriented hash mapping each header to the array of values across all rows. The natural complement to `to_hashes` for column-wise operations.
14
+
10
15
  ## [0.9.0] - 2026-04-19
11
16
 
12
17
  ### Added
@@ -112,7 +117,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
112
117
  - Type coercion and row validation
113
118
  - Quick load and filtering convenience methods
114
119
 
115
- [Unreleased]: https://github.com/philiprehberger/rb-csv-kit/compare/v0.9.0...HEAD
120
+ [Unreleased]: https://github.com/philiprehberger/rb-csv-kit/compare/v0.10.0...HEAD
121
+ [0.10.0]: https://github.com/philiprehberger/rb-csv-kit/releases/tag/v0.10.0
116
122
  [0.9.0]: https://github.com/philiprehberger/rb-csv-kit/compare/v0.8.0...v0.9.0
117
123
  [0.8.0]: https://github.com/philiprehberger/rb-csv-kit/compare/v0.7.0...v0.8.0
118
124
  [0.7.0]: https://github.com/philiprehberger/rb-csv-kit/compare/v0.6.0...v0.7.0
data/README.md CHANGED
@@ -205,11 +205,25 @@ delimiter = Philiprehberger::CsvKit::Detector.detect("data.tsv")
205
205
  # => "\t"
206
206
  ```
207
207
 
208
+ ### Column Transpose
209
+
210
+ ```ruby
211
+ require 'philiprehberger/csv_kit'
212
+
213
+ # users.csv:
214
+ # name,age
215
+ # Alice,30
216
+ # Bob,25
217
+ Philiprehberger::CsvKit.transpose('users.csv')
218
+ # => { name: ['Alice', 'Bob'], age: ['30', '25'] }
219
+ ```
220
+
208
221
  ## API
209
222
 
210
223
  | Method / Class | Description |
211
224
  |----------------|-------------|
212
225
  | `CsvKit.to_hashes(path_or_io, dialect:)` | Load CSV into array of symbolized hashes |
226
+ | `CsvKit.transpose(path_or_io, dialect:)` | Returns a column-oriented hash mapping each header to its column of values |
213
227
  | `CsvKit.to_csv(rows, headers:, dialect:)` | Serialize an array of hashes to a CSV string |
214
228
  | `CsvKit.sample(path_or_io, n, dialect:)` | Return n randomly sampled rows using reservoir sampling (Algorithm R) |
215
229
  | `CsvKit.pluck(path_or_io, *keys, dialect:)` | Extract specific columns |
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module CsvKit
5
- VERSION = '0.9.0'
5
+ VERSION = '0.10.0'
6
6
  end
7
7
  end
@@ -42,6 +42,20 @@ module Philiprehberger
42
42
  rows
43
43
  end
44
44
 
45
+ # Read a CSV and return a hash mapping each header to the column of values.
46
+ #
47
+ # @param path_or_io [String, IO] the path or IO to read from
48
+ # @param dialect [Hash, nil] optional CSV dialect overrides
49
+ # @return [Hash{Symbol => Array}] column-oriented view of the CSV
50
+ def self.transpose(path_or_io, dialect: nil)
51
+ rows = to_hashes(path_or_io, dialect: dialect)
52
+ return {} if rows.empty?
53
+
54
+ rows.first.keys.to_h do |key|
55
+ [key, rows.map { |row| row[key] }]
56
+ end
57
+ end
58
+
45
59
  # Serialize an array of hashes to a CSV string.
46
60
  #
47
61
  # If headers is omitted, the keys of the first hash are used. Empty input
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.9.0
4
+ version: 0.10.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-20 00:00:00.000000000 Z
11
+ date: 2026-05-07 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