csv-utils 0.3.9 → 0.3.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5b6f30da64b899586ef7d801904b8da9b01b6053f9d975f0702edcc5a7b65e0
4
- data.tar.gz: e7e5006c6b63a9b8472e4658c748071619d09adf0ca73a84109b43b8862f1bcd
3
+ metadata.gz: 8b2f52d8b1cfd29d0c74a0349bb889e1372da49c4d37986c38ff779d117a0eff
4
+ data.tar.gz: e67601c2eaf28e60e2d1dbc55ade05ddacb79a7ad350ff4c4667a0dbce6e046f
5
5
  SHA512:
6
- metadata.gz: 7ded9a4318f44f77b6c2ccf72a844a7cec734745052c62be5e19c2dbadc8e989b3c89528058fabfd63cbcb59a1575293b9cc87a343bb4d68dbad3051ba04616d
7
- data.tar.gz: dd8f0d7cd953eee05489423d0ef55e0b486500d2499d442d7d523636ced12858a2e9cec7ad60ce9d0126516121674d3c1e2a879ea89bb3a93cf7100709204b9d
6
+ metadata.gz: c6e5eb939a6c4a67977522dcbc7cfeb5c456cb2b890c046cf1adca7a6747eebc5fb534b9ba239e58e6c1fc74e90302f021bfcc34e8b5db6259dda8de98db9bbb
7
+ data.tar.gz: f5005436ad1f3f92f6f9c8aa350a2063779d15fbd4e86db9b3eb3aeb971efe5949798ef7853f6baed125f06e0fec9356ad0bce1a5087f3ffb84db82a49dfffae
data/csv-utils.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'csv-utils'
5
- s.version = '0.3.9'
5
+ s.version = '0.3.13'
6
6
  s.licenses = ['MIT']
7
7
  s.summary = 'CSV Utils'
8
8
  s.description = 'Tools for debugging malformed CSV files'
@@ -14,7 +14,7 @@ class CSVUtils::CSVIterator
14
14
  end
15
15
 
16
16
  def to_pretty_s
17
- reject { |_, v| v.strip.empty? }
17
+ reject { |_, v| v.nil? || v.strip.empty? }
18
18
  .each_with_index
19
19
  .map { |(k, v), idx| sprintf(' %-3d %s: %s', idx+1, k, v) }
20
20
  .join("\n") + "\n"
@@ -43,6 +43,27 @@ class CSVUtils::CSVIterator
43
43
  end
44
44
  end
45
45
 
46
+ def headers
47
+ @src_csv.rewind
48
+ @src_csv.shift
49
+ end
50
+
51
+ def to_hash(key, value = nil)
52
+ raise("header #{key} not found in #{headers}") unless headers.include?(key)
53
+ raise("headers #{value} not found in #{headers}") if value && !headers.include?(value)
54
+
55
+ value_proc =
56
+ if value
57
+ proc { |row| row[value] }
58
+ else
59
+ proc { |row| yield(row) }
60
+ end
61
+
62
+ each_with_object({}) do |row, hsh|
63
+ hsh[row[key]] = value_proc.call(row)
64
+ end
65
+ end
66
+
46
67
  private
47
68
 
48
69
  def strip_bom!(col)
@@ -107,6 +107,10 @@ class CSVUtils::CSVSort
107
107
  File.unlink(csv_part_file2)
108
108
  end
109
109
 
110
- FileUtils.mv(@csv_part_files.last || @csv_file, new_csv_file)
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.9
4
+ version: 0.3.13
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-03-12 00:00:00.000000000 Z
11
+ date: 2021-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inheritance-helper