csv-utils 0.3.10 → 0.3.14
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/csv-utils.gemspec +1 -1
- data/lib/csv_utils/csv_iterator.rb +23 -0
- data/lib/csv_utils/csv_sort.rb +5 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a15793e118aa3bd4175b59c6a17e7800dd322390f95ce55af29170a6422ae0c3
         | 
| 4 | 
            +
              data.tar.gz: 481c775dc66bc47fec11f5ab39f98a1a35020cb00f6e565761b47badc4d53ad8
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e987380b48bc309fbccb7bfd4311c8664077c8bac6ae31cf0c8c83f8035366f40fbdf60c8bf5b476e2a84e1899d6adada995fe81cd08531376511501700e2dca
         | 
| 7 | 
            +
              data.tar.gz: 020e3c5d08bbc1025b72fbde2de838efd45c24cf41ba89c9fb93cceb619e4184ec0c1671bf26b3ae1d9dad8978ce206359c53672bce843a3ac8651cc6ccf0412
         | 
    
        data/csv-utils.gemspec
    CHANGED
    
    
| @@ -43,6 +43,29 @@ class CSVUtils::CSVIterator | |
| 43 43 | 
             
                end
         | 
| 44 44 | 
             
              end
         | 
| 45 45 |  | 
| 46 | 
            +
              def headers
         | 
| 47 | 
            +
                @src_csv.rewind
         | 
| 48 | 
            +
                headers = @src_csv.shift
         | 
| 49 | 
            +
                strip_bom!(headers[0])
         | 
| 50 | 
            +
                headers
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              def to_hash(key, value = nil)
         | 
| 54 | 
            +
                raise("header #{key} not found in #{headers}") unless headers.include?(key)
         | 
| 55 | 
            +
                raise("headers #{value} not found in #{headers}") if value && !headers.include?(value)
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                value_proc =
         | 
| 58 | 
            +
                  if value
         | 
| 59 | 
            +
                    proc { |row| row[value] }
         | 
| 60 | 
            +
                  else
         | 
| 61 | 
            +
                    proc { |row| yield(row) }
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                each_with_object({}) do |row, hsh|
         | 
| 65 | 
            +
                  hsh[row[key]] = value_proc.call(row)
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
             | 
| 46 69 | 
             
              private
         | 
| 47 70 |  | 
| 48 71 | 
             
              def strip_bom!(col)
         | 
    
        data/lib/csv_utils/csv_sort.rb
    CHANGED
    
    | @@ -107,6 +107,10 @@ class CSVUtils::CSVSort | |
| 107 107 | 
             
                  File.unlink(csv_part_file2)
         | 
| 108 108 | 
             
                end
         | 
| 109 109 |  | 
| 110 | 
            -
                 | 
| 110 | 
            +
                if @csv_part_files.size > 0
         | 
| 111 | 
            +
                  FileUtils.mv(@csv_part_files.last, new_csv_file)
         | 
| 112 | 
            +
                else
         | 
| 113 | 
            +
                  FileUtils.cp(@csv_file, new_csv_file)
         | 
| 114 | 
            +
                end
         | 
| 111 115 | 
             
              end
         | 
| 112 116 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: csv-utils
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.3. | 
| 4 | 
            +
              version: 0.3.14
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Doug Youch
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2021- | 
| 11 | 
            +
            date: 2021-07-23 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: inheritance-helper
         |