smarter_csv 1.2.5 → 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: 8862baa01aeee087fce216ba9517d301d4deb70b8cf0c8d2a2b3c7bab81c693a
4
- data.tar.gz: bd5afb4bdcd925e5196beee967c70b60ef240a945d770554bc8b17f269c26ee4
3
+ metadata.gz: 79279f7e51fa65451092db03404d4c2b32e6fdf15107c931d35b6c8db094f68a
4
+ data.tar.gz: 6f930523b5c6e1bdc3e7d8a78d49bcbcc244437bd4e51d44d104768a4b3bb1c8
5
5
  SHA512:
6
- metadata.gz: f4e3080e4134aa9b59b729d4f4053426472a980d19c47d157a7175189e74f6cef6acde136f17c3be2a33e558dd9a6f85e5f7c62f35df4efffad64c9cabef2fee
7
- data.tar.gz: 11df1ee0862b61424187c30a0edef94186b656415fccfa4182c3fba09067c11a239b89bd302c03e97d984646fa3359281572254017cdc6f45c0a693e6c4d5130
6
+ metadata.gz: 93630aba89f0d6cbf7e311e3abbca51c5677edd3f653d978e98b54c2d251483dbf7951a5892dcaca7ca0d4d449eb5071fca35fac3f361bdf9bebfddbf7682673
7
+ data.tar.gz: 27164e53008600af9873c255bcde5f471ee41c3e6c808a1ed8087ab24a9008a5850dde3f57edac901a562cbb505c634132470827c55662ed7440612ce766f22b
data/.travis.yml CHANGED
@@ -6,10 +6,16 @@ before_install:
6
6
 
7
7
  matrix:
8
8
  include:
9
- - rvm: 2.2.8
10
- - rvm: 2.3.5
11
- - rvm: 2.4.2
12
- - rvm: jruby-9.1.15.0
9
+ - rvm: 2.2.10
10
+ - rvm: 2.3.8
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
13
19
  env:
14
20
  - JRUBY_OPTS="--server -Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -J-Xms512m -J-Xmx1024m"
15
21
  - rvm: ruby-head
data/Gemfile CHANGED
@@ -3,7 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in smarter_csv.gemspec
4
4
  gemspec
5
5
 
6
-
7
6
  gem "rake", "< 11"
8
7
  gem 'pry'
9
8
 
data/README.md CHANGED
@@ -324,6 +324,26 @@ 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
+
339
+ #### 1.2.8 (2020-02-04)
340
+ * fix deprecation warnings on Ruby 2.7 (thank to Diego Salido)
341
+
342
+ #### 1.2.7 (2020-02-03)
343
+
344
+ #### 1.2.6 (2018-11-13)
345
+ * fixing error caused by calling f.close when we do not hand in a file
346
+
327
347
  #### 1.2.5 (2018-09-16)
328
348
  * fixing issue #136 with comments in CSV files
329
349
  * fixing error class hierarchy
@@ -505,6 +525,7 @@ And a special thanks to those who contributed pull requests:
505
525
  * [Rohit Amarnath](https://github.com/ramarnat)
506
526
  * [Joshua Smith](https://github.com/enviable)
507
527
  * [Colin Petruno](https://github.com/colinpetruno)
528
+ * [Diego Salido](https://github.com/salidux)
508
529
 
509
530
 
510
531
  ## Contributing
@@ -53,7 +53,7 @@ module SmarterCSV
53
53
 
54
54
  if (header =~ %r{#{options[:quote_char]}}) and (! options[:force_simple_split])
55
55
  file_headerA = begin
56
- CSV.parse( header, csv_options ).flatten.collect!{|x| x.nil? ? '' : x} # to deal with nil values from CSV.parse
56
+ CSV.parse( header, **csv_options ).flatten.collect!{|x| x.nil? ? '' : x} # to deal with nil values from CSV.parse
57
57
  rescue CSV::MalformedCSVError => e
58
58
  raise $!, "#{$!} [SmarterCSV: csv line #{csv_line_count}]", $!.backtrace
59
59
  end
@@ -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
 
@@ -149,7 +149,7 @@ module SmarterCSV
149
149
 
150
150
  if (line =~ %r{#{options[:quote_char]}}) and (! options[:force_simple_split])
151
151
  dataA = begin
152
- CSV.parse( line, csv_options ).flatten.collect!{|x| x.nil? ? '' : x} # to deal with nil values from CSV.parse
152
+ CSV.parse( line, **csv_options ).flatten.collect!{|x| x.nil? ? '' : x} # to deal with nil values from CSV.parse
153
153
  rescue CSV::MalformedCSVError => e
154
154
  raise $!, "#{$!} [SmarterCSV: csv line #{csv_line_count}]", $!.backtrace
155
155
  end
@@ -248,7 +248,7 @@ module SmarterCSV
248
248
  end
249
249
  ensure
250
250
  $/ = old_row_sep # make sure this stupid global variable is always reset to it's previous value after we're done!
251
- f.close
251
+ f.close if f.respond_to?(:close)
252
252
  end
253
253
  if block_given?
254
254
  return chunk_count # when we do processing through a block we only care how many chunks we processed
@@ -1,3 +1,3 @@
1
1
  module SmarterCSV
2
- VERSION = "1.2.5"
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,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smarter_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'Tilo Sloboda
8
8
 
9
- '
10
- autorequire:
9
+ '
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-09-16 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
@@ -32,7 +32,7 @@ description: Ruby Gem for smarter importing of CSV Files as Array(s) of Hashes,
32
32
  email:
33
33
  - 'tilo.sloboda@gmail.com
34
34
 
35
- '
35
+ '
36
36
  executables: []
37
37
  extensions: []
38
38
  extra_rdoc_files: []
@@ -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
@@ -120,7 +121,7 @@ licenses:
120
121
  - MIT
121
122
  - GPL-2
122
123
  metadata: {}
123
- post_install_message:
124
+ post_install_message:
124
125
  rdoc_options: []
125
126
  require_paths:
126
127
  - lib
@@ -136,9 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
137
  version: '0'
137
138
  requirements:
138
139
  - csv
139
- rubyforge_project:
140
- rubygems_version: 2.7.7
141
- signing_key:
140
+ rubygems_version: 3.1.4
141
+ signing_key:
142
142
  specification_version: 4
143
143
  summary: Ruby Gem for smarter importing of CSV Files (and CSV-like files), with lots
144
144
  of optional features, e.g. chunked processing for huge CSV files
@@ -154,6 +154,7 @@ test_files:
154
154
  - spec/fixtures/empty.csv
155
155
  - spec/fixtures/ignore_comments.csv
156
156
  - spec/fixtures/ignore_comments2.csv
157
+ - spec/fixtures/key_mapping.csv
157
158
  - spec/fixtures/line_endings_n.csv
158
159
  - spec/fixtures/line_endings_r.csv
159
160
  - spec/fixtures/line_endings_rn.csv