smarter_csv 1.2.8 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -6
- data/README.md +12 -0
- data/lib/smarter_csv/smarter_csv.rb +1 -1
- data/lib/smarter_csv/version.rb +1 -1
- data/smarter_csv.gemspec +1 -1
- data/spec/fixtures/key_mapping.csv +2 -0
- data/spec/smarter_csv/key_mapping_spec.rb +31 -0
- data/spec/smarter_csv/malformed_spec.rb +0 -4
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79279f7e51fa65451092db03404d4c2b32e6fdf15107c931d35b6c8db094f68a
|
4
|
+
data.tar.gz: 6f930523b5c6e1bdc3e7d8a78d49bcbcc244437bd4e51d44d104768a4b3bb1c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
12
|
-
- rvm: 2.5.
|
13
|
-
- rvm: 2.6.
|
14
|
-
- rvm: 2.7.
|
15
|
-
- rvm: 3.0.
|
16
|
-
- rvm:
|
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]
|
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
|
|
data/lib/smarter_csv/version.rb
CHANGED
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
|
@@ -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.
|
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:
|
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.
|
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
|