strong_csv 0.8.0 → 0.8.2
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/lib/strong_csv/let.rb +1 -1
 - data/lib/strong_csv/version.rb +1 -1
 - data/lib/strong_csv.rb +16 -1
 - metadata +3 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 87d85fbdffebb9ee14657c9fe09099df0dba44c196c8da8de01518e157f4d4ca
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 74575a412ddababb78fbb053b9fbd0ace06cc83ee27a5ac85be90e1eb91b4e08
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 0be982e1c85e044466ffba782e74e037e20365b080450f078223be1285b787570038258a705bb8e21caaf7c45a1f3e57b041f7a0ffb62e16d97237b0296698e3
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e9ebbeae9e5993c10b655f2626a17bcdbb6e6abbb9ecdd66b9e8e60d24fedf63a7d2e59552930b2c7897b8795a590e55409eb8fd836353184955d419ba37acb9
         
     | 
    
        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.2
         
     | 
| 
       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 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2023-09-03 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.
         
     | 
| 
         @@ -42,7 +42,6 @@ licenses: 
     | 
|
| 
       42 
42 
     | 
    
         
             
            metadata:
         
     | 
| 
       43 
43 
     | 
    
         
             
              homepage_uri: https://github.com/yykamei/strong_csv
         
     | 
| 
       44 
44 
     | 
    
         
             
              source_code_uri: https://github.com/yykamei/strong_csv
         
     | 
| 
       45 
     | 
    
         
            -
              changelog_uri: https://github.com/yykamei/strong_csv/blob/main/CHANGELOG.md
         
     | 
| 
       46 
45 
     | 
    
         
             
              rubygems_mfa_required: 'true'
         
     | 
| 
       47 
46 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       48 
47 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
         @@ -59,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       59 
58 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       60 
59 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       61 
60 
     | 
    
         
             
            requirements: []
         
     | 
| 
       62 
     | 
    
         
            -
            rubygems_version: 3.4. 
     | 
| 
      
 61 
     | 
    
         
            +
            rubygems_version: 3.4.10
         
     | 
| 
       63 
62 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       64 
63 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       65 
64 
     | 
    
         
             
            summary: Type check CSV objects
         
     |