smarter_csv 1.6.0 → 1.6.1

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: fd2cf82aafc3b45257fbdfc594ed8e1d3bf2226e59cbee144b3003d8f79ec6cf
4
- data.tar.gz: 95df862865e3123cf86194d47107f140f69f2fc91c20aba01d4004e8bffa5d74
3
+ metadata.gz: 9be5f053e15e157d7d28555b4de894d2761d5918203da45f5fc4e6c5adcc2a3f
4
+ data.tar.gz: a47394f3d1f985960a64abf1a43ce6ebf9b8217af2c01a0c5f053af8c77c09ae
5
5
  SHA512:
6
- metadata.gz: df32ae9a380fa4fff0932d56e8a0cacadb8d4ebf7d8124e607f2ba389c3b60f875c300a2137fe04aac2b7eda77850b343af5e58c53e310f90460f96223f3228c
7
- data.tar.gz: 107e1dbacdc6293a0c044a91cf237f50fbeab59eb5b032167f55d0fe6c2cf07b079c6cfe296368c03d2c84e64ce3c0e6ad744043397cdc217cd3ab51beb3ab09
6
+ metadata.gz: f27113af8a5771d89ac5c8783f1f69645c24bb576dafd97de17b0d8db8fff74dc396b42450802f9332c9f8b32a02ee18dabbc5dbc2daa91c75f957a678e99099
7
+ data.tar.gz: 5b2c2f3cbfc17b43c030c4c4c261962818bfbb2ce1a0ecd88f394682b75b75a64a2d8b6afcc0e4b99b97d39ef4b645de143cbb5f595e7aa9d661e66b1a53e98f
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
 
2
2
  # SmarterCSV 1.x Change Log
3
3
 
4
+ ## 1.6.1 (2022-05-06)
5
+ * unused keys in `key_mapping` generate a warning, no longer raise an exception
6
+
4
7
  ## 1.6.0 (2022-05-03)
5
8
  * completely rewrote line parser
6
9
  * added methods `SmarterCSV.raw_headers` and `SmarterCSV.headers` to allow easy examination of how the headers are processed.
@@ -62,6 +62,7 @@ module SmarterCSV
62
62
  # cater for the quoted csv data containing the row separator carriage return character
63
63
  # in which case the row data will be split across multiple lines (see the sample content in spec/fixtures/carriage_returns_rn.csv)
64
64
  # by detecting the existence of an uneven number of quote characters
65
+
65
66
  multiline = line.count(options[:quote_char])%2 == 1 # should handle quote_char nil
66
67
  while line.count(options[:quote_char])%2 == 1 # should handle quote_char nil
67
68
  next_line = fh.readline(options[:row_sep])
@@ -75,7 +76,6 @@ module SmarterCSV
75
76
 
76
77
  dataA, data_size = parse(line, options, header_size)
77
78
 
78
- dataA.map!{|x| x.sub(/(#{options[:col_sep]})+\z/, '')} # remove any unwanted trailing col_sep characters at the end
79
79
  dataA.map!{|x| x.strip} if options[:strip_whitespace]
80
80
 
81
81
  # if all values are blank, then ignore this line
@@ -420,7 +420,7 @@ module SmarterCSV
420
420
  if ! key_mappingH.nil? && key_mappingH.class == Hash && key_mappingH.keys.size > 0
421
421
  # we can't map keys that are not there
422
422
  missing_keys = key_mappingH.keys - headerA
423
- raise(SmarterCSV::KeyMappingError, "missing header(s): #{missing_keys.join(",")}") unless missing_keys.empty?
423
+ puts "WARNING: missing header(s): #{missing_keys.join(",")}" unless missing_keys.empty?
424
424
 
425
425
  headerA.map!{|x| key_mappingH.has_key?(x) ? (key_mappingH[x].nil? ? nil : key_mappingH[x]) : (options[:remove_unmapped_keys] ? nil : x)}
426
426
  end
@@ -1,3 +1,3 @@
1
1
  module SmarterCSV
2
- VERSION = "1.6.0"
2
+ VERSION = "1.6.1"
3
3
  end
@@ -17,12 +17,12 @@ describe 'duplicate headers' do
17
17
  }.to raise_exception(SmarterCSV::DuplicateHeaders)
18
18
  end
19
19
 
20
- it 'raises error on missing mapped headers and includes missing headers in message' do
20
+ it 'does not raise error on missing mapped headers and includes missing headers in message' do
21
+ # the mapping is right, but the underlying csv file is bad
22
+ options = {:key_mapping => {:email => :a, :firstname => :b, :lastname => :c, :manager_email => :d, :age => :e} }
21
23
  expect {
22
- # the mapping is right, but the underlying csv file is bad
23
- options = {:key_mapping => {:email => :a, :firstname => :b, :lastname => :c, :manager_email => :d, :age => :e} }
24
24
  SmarterCSV.process("#{fixture_path}/duplicate_headers.csv", options)
25
- }.to raise_exception(SmarterCSV::KeyMappingError, "missing header(s): manager_email")
25
+ }.not_to raise_exception(SmarterCSV::KeyMappingError)
26
26
  end
27
27
  end
28
28
 
@@ -28,11 +28,11 @@ describe 'test exceptions for invalid headers' do
28
28
  }.to raise_exception(SmarterCSV::MissingHeaders)
29
29
  end
30
30
 
31
- it 'raises error on missing mapped headers and includes missing headers in message' do
31
+ it 'does not raise error on missing mapped headers and includes missing headers in message' do
32
+ # :age does not exist in the CSV header
33
+ options = {:key_mapping => {:email => :a, :firstname => :b, :lastname => :c, :manager_email => :d, :age => :e} }
32
34
  expect {
33
- # :age does not exist in the CSV header
34
- options = {:key_mapping => {:email => :a, :firstname => :b, :lastname => :c, :manager_email => :d, :age => :e} }
35
35
  SmarterCSV.process("#{fixture_path}/user_import.csv", options)
36
- }.to raise_exception(SmarterCSV::KeyMappingError, "missing header(s): age")
36
+ }.not_to raise_exception(SmarterCSV::KeyMappingError)
37
37
  end
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smarter_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilo Sloboda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-03 00:00:00.000000000 Z
11
+ date: 2022-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec