csv-utils 0.3.11 → 0.3.12

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: 615d0207e2fd53304c2c9ae1c1f269627ab56cfdfd7075359989e0cc24ef7c27
4
- data.tar.gz: 834780d9dfbde10d04c9a85da5259720e6f59d30649dcb5a3e0daf986533bd83
3
+ metadata.gz: d7b43801f0f7e62d34d8a77508964f0b6ea054a3ac2c8d17bf42d22aa0b245bd
4
+ data.tar.gz: ccd3282e4c7b1e1985439e24a159fe09c570b18446adee2b8db4776bc6024852
5
5
  SHA512:
6
- metadata.gz: bbfb3c0ebae643ec97c6888e47347c191cbfd5ed43359d84de14de4e17238cf41db4021113bc599988168007777b99431713094c4eb53bef2a7f4cb2e61aad72
7
- data.tar.gz: 40816128c4d6410e4a094cd35962d57d302cff5d294f3a6c43eb18ea55de5440a1ebed69137d2e9c5a309044a0028ff569b49f0ce61768fb1216ee5233e5cf0d
6
+ metadata.gz: 1684319de3c4f728f55e1c201790dd5cc3aa110e09d14a4043fcdf3b70c02568fe898c4f2d7b839e633f461294f9870fae0a8cf2d3d785d173aa66f9c8ba2ab1
7
+ data.tar.gz: 6e7689f6f544e5280dbf144dc5a23a4b088aeff6c06931c0a856f6cd16353048e4ed343da0406550d2e7f48abd8af6e1ef31f6114ec9f3435aa56815c5fea24b
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.11'
5
+ s.version = '0.3.12'
6
6
  s.licenses = ['MIT']
7
7
  s.summary = 'CSV Utils'
8
8
  s.description = 'Tools for debugging malformed CSV files'
@@ -43,6 +43,26 @@ class CSVUtils::CSVIterator
43
43
  end
44
44
  end
45
45
 
46
+ def headers
47
+ first.keys
48
+ end
49
+
50
+ def to_hash(key, value = nil)
51
+ raise("header #{key} not found in #{headers}") unless headers.include?(key)
52
+ raise("headers #{value} not found in #{headers}") if value && !headers.include?(value)
53
+
54
+ value_proc =
55
+ if value
56
+ proc { |row| row[value] }
57
+ else
58
+ proc { |row| yield(row) }
59
+ end
60
+
61
+ each_with_object({}) do |row, hsh|
62
+ hsh[row[key]] = value_proc.call(row)
63
+ end
64
+ end
65
+
46
66
  private
47
67
 
48
68
  def strip_bom!(col)
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.11
4
+ version: 0.3.12
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-23 00:00:00.000000000 Z
11
+ date: 2021-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inheritance-helper