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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bf72430d106db5258d3dc4a32d4c2c1a5bfa0ab0fd74b0e958efe1bf073e942
4
- data.tar.gz: 51d96be97ee05967b85b4e09a57822678cdf755121aa01fc5e185dc9bdcc976a
3
+ metadata.gz: 9d6c372310291e7aedde75e8c09a4231d3dd60819b4b143e23cd03ae50785d45
4
+ data.tar.gz: e916208b99620540db4e8805803f50d5a016482c4eafa256b7acd9bdf4d52d6e
5
5
  SHA512:
6
- metadata.gz: 131ac972c42725f4049fde7f9c11d5226b245b11a650456079e49d4bb95a379f0b44657257e5d0738547fb2adcf16ff63c6e78b0a8f773491124936de9f0490e
7
- data.tar.gz: bb9f719790fe36f6991a93fa18619723c33549c7fd9a7c597926bc0793ad5cdfc572ae886070681d7af08b7a6817e4067681ceeee081f262cd20e8a00b427a45
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
- Note the numbers must start from `0` (zero-based index).
112
+
113
+ > [!NOTE]
114
+ > The numbers must start from `0` (zero-based index).
113
115
 
114
116
  ```ruby
115
117
  StrongCSV.new do
@@ -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 = types.empty? ? type : Types::Union.new(type, *types)
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class StrongCSV
4
- VERSION = "0.8.1"
4
+ VERSION = "0.8.3"
5
5
  end
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.each.map { |row| Row.new(row: row, types: @let.types, lineno: csv.lineno) }
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.1
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: 2023-03-29 00:00:00.000000000 Z
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.4.6
61
+ rubygems_version: 3.5.3
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Type check CSV objects