strong_csv 0.8.1 → 0.8.3
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 +4 -4
- data/README.md +3 -1
- data/lib/strong_csv/let.rb +1 -1
- data/lib/strong_csv/version.rb +1 -1
- data/lib/strong_csv.rb +16 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d6c372310291e7aedde75e8c09a4231d3dd60819b4b143e23cd03ae50785d45
|
4
|
+
data.tar.gz: e916208b99620540db4e8805803f50d5a016482c4eafa256b7acd9bdf4d52d6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f728fae32610b9bb8c0d35653f9f40e1e8004edda81cc2ce220fbacbd636713f15225a793e61afe9ea79ae355427af8bbae90c32c7de69fe618a0ec98a7fef1b
|
7
|
+
data.tar.gz: 3038395bbe8813d0741237c37a740e058638b1509c9d8c5fbaca0d45dbbee03667b1813837699bd5280f0e685bb762cb32c4fa5189efae04983253d42fa8d7dc
|
data/README.md
CHANGED
@@ -109,7 +109,9 @@ end
|
|
109
109
|
```
|
110
110
|
|
111
111
|
You can also define types without CSV headers by specifying column numbers.
|
112
|
-
|
112
|
+
|
113
|
+
> [!NOTE]
|
114
|
+
> The numbers must start from `0` (zero-based index).
|
113
115
|
|
114
116
|
```ruby
|
115
117
|
StrongCSV.new do
|
data/lib/strong_csv/let.rb
CHANGED
@@ -23,7 +23,7 @@ class StrongCSV
|
|
23
23
|
# @param type [StrongCSV::Type::Base]
|
24
24
|
# @param types [Array<StrongCSV::Type::Base>]
|
25
25
|
def let(name, type, *types, error_message: nil, &block)
|
26
|
-
type =
|
26
|
+
type = Types::Union.new(type, *types) unless types.empty?
|
27
27
|
case name
|
28
28
|
when ::Integer
|
29
29
|
@types << TypeWrapper.new(name: name, type: type, block: block, error_message: error_message)
|
data/lib/strong_csv/version.rb
CHANGED
data/lib/strong_csv.rb
CHANGED
@@ -21,6 +21,21 @@ require_relative "strong_csv/let"
|
|
21
21
|
require_relative "strong_csv/row"
|
22
22
|
|
23
23
|
# StrongCSV is a library for parsing CSV contents with type checking.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# strong_csv = StrongCSV.new do
|
27
|
+
# let :name, string(within: 1..255)
|
28
|
+
# let :score, integer
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# result = strong_csv.parse(<<~CSV)
|
32
|
+
# name,score
|
33
|
+
# JJ,X
|
34
|
+
# Tomo,23
|
35
|
+
# Haru,9
|
36
|
+
# CSV
|
37
|
+
# result.map(&:valid?) # => [false, true, true]
|
38
|
+
#
|
24
39
|
class StrongCSV
|
25
40
|
class Error < StandardError; end
|
26
41
|
|
@@ -47,7 +62,7 @@ class StrongCSV
|
|
47
62
|
yield Row.new(row: row, types: @let.types, lineno: csv.lineno)
|
48
63
|
end
|
49
64
|
else
|
50
|
-
csv.
|
65
|
+
csv.map { |row| Row.new(row: row, types: @let.types, lineno: csv.lineno) }
|
51
66
|
end
|
52
67
|
end
|
53
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strong_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yutaka Kamei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: strong_csv is a type checker for a CSV file. It lets developers declare
|
14
14
|
types for each column to ensure all cells are satisfied with desired types.
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '0'
|
60
60
|
requirements: []
|
61
|
-
rubygems_version: 3.
|
61
|
+
rubygems_version: 3.5.3
|
62
62
|
signing_key:
|
63
63
|
specification_version: 4
|
64
64
|
summary: Type check CSV objects
|