smarter_csv 1.2.8 → 1.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90df8a442690ff9202ee2762a199e652ebca4dc6e5899d24ee0a72d192cf539f
4
- data.tar.gz: 16d4826bc7840a112ef5d5ea3b7acf0997d5fbeb46f8f5289ffa31a7356aa71c
3
+ metadata.gz: 79279f7e51fa65451092db03404d4c2b32e6fdf15107c931d35b6c8db094f68a
4
+ data.tar.gz: 6f930523b5c6e1bdc3e7d8a78d49bcbcc244437bd4e51d44d104768a4b3bb1c8
5
5
  SHA512:
6
- metadata.gz: 85cf20915d26794ba37e508379bc8460d65f054771803779df3b67cd907a61da9ea195d8b51da5a9942bb7f3a5866325114a7a107cbbfcc269f47f6bf6dbfff5
7
- data.tar.gz: e2508804722db4bd76e63a9e459b180fb75f7215e3e6d53970e5a83c120d0dab3cdd639c562abfe91d5b9458c3a990aa3959e85000491aef8529442ade5a3f90
6
+ metadata.gz: 93630aba89f0d6cbf7e311e3abbca51c5677edd3f653d978e98b54c2d251483dbf7951a5892dcaca7ca0d4d449eb5071fca35fac3f361bdf9bebfddbf7682673
7
+ data.tar.gz: 27164e53008600af9873c255bcde5f471ee41c3e6c808a1ed8087ab24a9008a5850dde3f57edac901a562cbb505c634132470827c55662ed7440612ce766f22b
data/.travis.yml CHANGED
@@ -8,12 +8,14 @@ matrix:
8
8
  include:
9
9
  - rvm: 2.2.10
10
10
  - rvm: 2.3.8
11
- - rvm: 2.4.6
12
- - rvm: 2.5.7
13
- - rvm: 2.6.3
14
- - rvm: 2.7.2
15
- - rvm: 3.0.0
16
- - rvm: jruby-9.2.7.0
11
+ - rvm: 2.4.10
12
+ - rvm: 2.5.8
13
+ - rvm: 2.6.9
14
+ - rvm: 2.7.5
15
+ - rvm: 3.0.3
16
+ - rvm: 3.1.0
17
+ - rvm: jruby-9.2.19.0
18
+ - rvm: jruby-9.3.3.0
17
19
  env:
18
20
  - JRUBY_OPTS="--server -Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -J-Xms512m -J-Xmx1024m"
19
21
  - rvm: ruby-head
data/README.md CHANGED
@@ -324,6 +324,18 @@ Planned in the next releases:
324
324
 
325
325
  ## Changes
326
326
 
327
+ #### 1.3.0 (2022-01-06) Breaking code change if you used `--key_mappings`
328
+ * fix bug for key_mappings (issue #181)
329
+ The values of the `key_mappings` hash will now be used "as is", and no longer forced to be symbols
330
+
331
+ **Users with existing code with `--key_mappings` need to change their code** to
332
+ * either use symbols in the `key_mapping` hash
333
+ * or change the expected keys from symbols to strings
334
+
335
+ #### 1.2.9 (2021-11-22) (PULLED)
336
+ * fix bug for key_mappings (issue #181)
337
+ The values of the `key_mappings` hash will now be used "as is", and no longer forced to be symbols
338
+
327
339
  #### 1.2.8 (2020-02-04)
328
340
  * fix deprecation warnings on Ruby 2.7 (thank to Diego Salido)
329
341
 
@@ -92,7 +92,7 @@ module SmarterCSV
92
92
  # do some key mapping on the keys in the file header
93
93
  # if you want to completely delete a key, then map it to nil or to ''
94
94
  if ! key_mappingH.nil? && key_mappingH.class == Hash && key_mappingH.keys.size > 0
95
- headerA.map!{|x| key_mappingH.has_key?(x) ? (key_mappingH[x].nil? ? nil : key_mappingH[x].to_sym) : (options[:remove_unmapped_keys] ? nil : x)}
95
+ headerA.map!{|x| key_mappingH.has_key?(x) ? (key_mappingH[x].nil? ? nil : key_mappingH[x]) : (options[:remove_unmapped_keys] ? nil : x)}
96
96
  end
97
97
  end
98
98
 
@@ -1,3 +1,3 @@
1
1
  module SmarterCSV
2
- VERSION = "1.2.8"
2
+ VERSION = "1.3.0"
3
3
  end
data/smarter_csv.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.requirements = ['csv'] # for CSV.parse() only needed in case we have quoted fields
17
17
  gem.version = SmarterCSV::VERSION
18
- gem.licenses = ['MIT','GPL-2']
18
+ gem.licenses = ['MIT','GPL-2'] # pick either of these licenses - only that license applies to you
19
19
  gem.add_development_dependency "rspec"
20
20
  # gem.add_development_dependency "guard-rspec"
21
21
  end
@@ -0,0 +1,2 @@
1
+ THIS,THAT,other
2
+ this,that,other
@@ -22,4 +22,35 @@ describe 'be_able_to' do
22
22
  end
23
23
  end
24
24
 
25
+ describe 'when keep_original_headers' do
26
+ it 'without key mapping' do
27
+ options = {:keep_original_headers => true}
28
+ data = SmarterCSV.process("#{fixture_path}/key_mapping.csv", options)
29
+ data.size.should == 1
30
+ data.first.keys.should == ['THIS', 'THAT', 'other']
31
+ end
32
+
33
+ it 'sets key_mapping to a symbol' do
34
+ options = {:keep_original_headers => true, :key_mapping => {'other' => :other}}
35
+ data = SmarterCSV.process("#{fixture_path}/key_mapping.csv", options)
36
+ data.size.should == 1
37
+ data.first.keys.should == ['THIS', 'THAT', :other]
38
+ end
39
+
40
+ # this previously would set the key to a symbol :OTHER, which was a bug!
41
+ it 'sets key_mapping to a string' do
42
+ options = {:keep_original_headers => true, :key_mapping => {'other' => 'OTHER'}}
43
+ data = SmarterCSV.process("#{fixture_path}/key_mapping.csv", options)
44
+ data.size.should == 1
45
+ data.first.keys.should == ['THIS', 'THAT', 'OTHER']
46
+ end
47
+
48
+ # users now have to explicitly set this to a symbol, or change the expected keys to be strings.
49
+ it 'sets key_mapping to a symbol' do
50
+ options = {:keep_original_headers => true, :key_mapping => {'other' => :OTHER}}
51
+ data = SmarterCSV.process("#{fixture_path}/key_mapping.csv", options)
52
+ data.size.should == 1
53
+ data.first.keys.should == ['THIS', 'THAT', :OTHER]
54
+ end
55
+ end
25
56
  end
@@ -8,14 +8,10 @@ describe 'malformed_csv' do
8
8
  context "malformed header" do
9
9
  let(:csv_path) { "#{fixture_path}/malformed_header.csv" }
10
10
  it { should raise_error(CSV::MalformedCSVError) }
11
- it { should raise_error(/(Missing or stray quote in line 1|CSV::MalformedCSVError)/) }
12
- it { should raise_error(CSV::MalformedCSVError) }
13
11
  end
14
12
 
15
13
  context "malformed content" do
16
14
  let(:csv_path) { "#{fixture_path}/malformed.csv" }
17
15
  it { should raise_error(CSV::MalformedCSVError) }
18
- it { should raise_error(/(Missing or stray quote in line 1|CSV::MalformedCSVError)/) }
19
- it { should raise_error(CSV::MalformedCSVError) }
20
16
  end
21
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smarter_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.8
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'Tilo Sloboda
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-02-04 00:00:00.000000000 Z
13
+ date: 2022-02-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -60,6 +60,7 @@ files:
60
60
  - spec/fixtures/empty.csv
61
61
  - spec/fixtures/ignore_comments.csv
62
62
  - spec/fixtures/ignore_comments2.csv
63
+ - spec/fixtures/key_mapping.csv
63
64
  - spec/fixtures/line_endings_n.csv
64
65
  - spec/fixtures/line_endings_r.csv
65
66
  - spec/fixtures/line_endings_rn.csv
@@ -136,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
137
  version: '0'
137
138
  requirements:
138
139
  - csv
139
- rubygems_version: 3.0.6
140
+ rubygems_version: 3.1.4
140
141
  signing_key:
141
142
  specification_version: 4
142
143
  summary: Ruby Gem for smarter importing of CSV Files (and CSV-like files), with lots
@@ -153,6 +154,7 @@ test_files:
153
154
  - spec/fixtures/empty.csv
154
155
  - spec/fixtures/ignore_comments.csv
155
156
  - spec/fixtures/ignore_comments2.csv
157
+ - spec/fixtures/key_mapping.csv
156
158
  - spec/fixtures/line_endings_n.csv
157
159
  - spec/fixtures/line_endings_r.csv
158
160
  - spec/fixtures/line_endings_rn.csv