smarter_csv 1.2.7 → 1.4.2

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.
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ fixture_path = 'spec/fixtures'
4
+
5
+ describe 'can handle empty columns' do
6
+
7
+ describe 'default behavior' do
8
+ it 'has empty columns at end' do
9
+ data = SmarterCSV.process("#{fixture_path}/empty_columns_1.csv")
10
+ data.size.should eq 1
11
+ item = data.first
12
+ item[:id].should == 123
13
+ item[:col1].should == nil
14
+ item[:col2].should == nil
15
+ item[:col3].should == nil
16
+ end
17
+
18
+ it 'has empty columns in the middle' do
19
+ data = SmarterCSV.process("#{fixture_path}/empty_columns_2.csv")
20
+ data.size.should eq 1
21
+ item = data.first
22
+ item[:id].should == 123
23
+ item[:col1].should == nil
24
+ item[:col2].should == nil
25
+ item[:col3].should == 1
26
+ end
27
+ end
28
+
29
+ describe 'with remove_empty_values: true' do
30
+ options = {remove_empty_values: true}
31
+ it 'has empty columns at end' do
32
+ data = SmarterCSV.process("#{fixture_path}/empty_columns_1.csv", options)
33
+ data.size.should eq 1
34
+ item = data.first
35
+ item[:id].should == 123
36
+ item[:col1].should == nil
37
+ item[:col2].should == nil
38
+ item[:col3].should == nil
39
+ end
40
+
41
+ it 'has empty columns in the middle' do
42
+ data = SmarterCSV.process("#{fixture_path}/empty_columns_2.csv", options)
43
+ data.size.should eq 1
44
+ item = data.first
45
+ item[:id].should == 123
46
+ item[:col1].should == nil
47
+ item[:col2].should == nil
48
+ item[:col3].should == 1
49
+ end
50
+ end
51
+
52
+ describe 'with remove_empty_values: false' do
53
+ options = {remove_empty_values: false}
54
+ it 'has empty columns at end' do
55
+ data = SmarterCSV.process("#{fixture_path}/empty_columns_1.csv", options)
56
+ data.size.should eq 1
57
+ item = data.first
58
+ item[:id].should == 123
59
+ item[:col1].should == ''
60
+ item[:col2].should == ''
61
+ item[:col3].should == ''
62
+ end
63
+
64
+ it 'has empty columns in the middle' do
65
+ data = SmarterCSV.process("#{fixture_path}/empty_columns_2.csv", options)
66
+ data.size.should eq 1
67
+ item = data.first
68
+ item[:id].should == 123
69
+ item[:col1].should == ''
70
+ item[:col2].should == ''
71
+ item[:col3].should == 1
72
+ end
73
+ end
74
+ 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,16 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smarter_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
- - 'Tilo Sloboda
8
-
9
- '
7
+ - Tilo Sloboda
10
8
  autorequire:
11
9
  bindir: bin
12
10
  cert_chain: []
13
- date: 2021-02-04 00:00:00.000000000 Z
11
+ date: 2022-02-15 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
14
  name: rspec
@@ -26,13 +24,25 @@ dependencies:
26
24
  - - ">="
27
25
  - !ruby/object:Gem::Version
28
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: simplecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
29
41
  description: Ruby Gem for smarter importing of CSV Files as Array(s) of Hashes, with
30
42
  optional features for processing large files in parallel, embedded comments, unusual
31
43
  field- and record-separators, flexible mapping of CSV-headers to Hash-keys
32
44
  email:
33
- - 'tilo.sloboda@gmail.com
34
-
35
- '
45
+ - tilo.sloboda@gmail.com
36
46
  executables: []
37
47
  extensions: []
38
48
  extra_rdoc_files: []
@@ -41,7 +51,10 @@ files:
41
51
  - ".rspec"
42
52
  - ".rvmrc"
43
53
  - ".travis.yml"
54
+ - CHANGELOG.md
55
+ - CONTRIBUTORS.md
44
56
  - Gemfile
57
+ - LICENSE.txt
45
58
  - README.md
46
59
  - Rakefile
47
60
  - lib/extensions/hash.rb
@@ -58,8 +71,11 @@ files:
58
71
  - spec/fixtures/chunk_cornercase.csv
59
72
  - spec/fixtures/duplicate_headers.csv
60
73
  - spec/fixtures/empty.csv
74
+ - spec/fixtures/empty_columns_1.csv
75
+ - spec/fixtures/empty_columns_2.csv
61
76
  - spec/fixtures/ignore_comments.csv
62
77
  - spec/fixtures/ignore_comments2.csv
78
+ - spec/fixtures/key_mapping.csv
63
79
  - spec/fixtures/line_endings_n.csv
64
80
  - spec/fixtures/line_endings_r.csv
65
81
  - spec/fixtures/line_endings_rn.csv
@@ -74,7 +90,11 @@ files:
74
90
  - spec/fixtures/quote_char.csv
75
91
  - spec/fixtures/quoted.csv
76
92
  - spec/fixtures/quoted2.csv
77
- - spec/fixtures/separator.csv
93
+ - spec/fixtures/separator_colon.csv
94
+ - spec/fixtures/separator_comma.csv
95
+ - spec/fixtures/separator_pipe.csv
96
+ - spec/fixtures/separator_semi.csv
97
+ - spec/fixtures/separator_tab.csv
78
98
  - spec/fixtures/skip_lines.csv
79
99
  - spec/fixtures/trading.csv
80
100
  - spec/fixtures/user_import.csv
@@ -83,11 +103,13 @@ files:
83
103
  - spec/fixtures/with_dates.csv
84
104
  - spec/smarter_csv/binary_file2_spec.rb
85
105
  - spec/smarter_csv/binary_file_spec.rb
106
+ - spec/smarter_csv/blank_spec.rb
86
107
  - spec/smarter_csv/carriage_return_spec.rb
87
108
  - spec/smarter_csv/chunked_reading_spec.rb
88
109
  - spec/smarter_csv/close_file_spec.rb
89
110
  - spec/smarter_csv/column_separator_spec.rb
90
111
  - spec/smarter_csv/convert_values_to_numeric_spec.rb
112
+ - spec/smarter_csv/empty_columns_spec.rb
91
113
  - spec/smarter_csv/extenstions_spec.rb
92
114
  - spec/smarter_csv/header_transformation_spec.rb
93
115
  - spec/smarter_csv/ignore_comments_spec.rb
@@ -118,8 +140,8 @@ files:
118
140
  homepage: https://github.com/tilo/smarter_csv
119
141
  licenses:
120
142
  - MIT
121
- - GPL-2
122
- metadata: {}
143
+ metadata:
144
+ homepage_uri: https://github.com/tilo/smarter_csv
123
145
  post_install_message:
124
146
  rdoc_options: []
125
147
  require_paths:
@@ -136,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
158
  version: '0'
137
159
  requirements:
138
160
  - csv
139
- rubygems_version: 3.0.6
161
+ rubygems_version: 3.1.6
140
162
  signing_key:
141
163
  specification_version: 4
142
164
  summary: Ruby Gem for smarter importing of CSV Files (and CSV-like files), with lots
@@ -151,8 +173,11 @@ test_files:
151
173
  - spec/fixtures/chunk_cornercase.csv
152
174
  - spec/fixtures/duplicate_headers.csv
153
175
  - spec/fixtures/empty.csv
176
+ - spec/fixtures/empty_columns_1.csv
177
+ - spec/fixtures/empty_columns_2.csv
154
178
  - spec/fixtures/ignore_comments.csv
155
179
  - spec/fixtures/ignore_comments2.csv
180
+ - spec/fixtures/key_mapping.csv
156
181
  - spec/fixtures/line_endings_n.csv
157
182
  - spec/fixtures/line_endings_r.csv
158
183
  - spec/fixtures/line_endings_rn.csv
@@ -167,7 +192,11 @@ test_files:
167
192
  - spec/fixtures/quote_char.csv
168
193
  - spec/fixtures/quoted.csv
169
194
  - spec/fixtures/quoted2.csv
170
- - spec/fixtures/separator.csv
195
+ - spec/fixtures/separator_colon.csv
196
+ - spec/fixtures/separator_comma.csv
197
+ - spec/fixtures/separator_pipe.csv
198
+ - spec/fixtures/separator_semi.csv
199
+ - spec/fixtures/separator_tab.csv
171
200
  - spec/fixtures/skip_lines.csv
172
201
  - spec/fixtures/trading.csv
173
202
  - spec/fixtures/user_import.csv
@@ -176,11 +205,13 @@ test_files:
176
205
  - spec/fixtures/with_dates.csv
177
206
  - spec/smarter_csv/binary_file2_spec.rb
178
207
  - spec/smarter_csv/binary_file_spec.rb
208
+ - spec/smarter_csv/blank_spec.rb
179
209
  - spec/smarter_csv/carriage_return_spec.rb
180
210
  - spec/smarter_csv/chunked_reading_spec.rb
181
211
  - spec/smarter_csv/close_file_spec.rb
182
212
  - spec/smarter_csv/column_separator_spec.rb
183
213
  - spec/smarter_csv/convert_values_to_numeric_spec.rb
214
+ - spec/smarter_csv/empty_columns_spec.rb
184
215
  - spec/smarter_csv/extenstions_spec.rb
185
216
  - spec/smarter_csv/header_transformation_spec.rb
186
217
  - spec/smarter_csv/ignore_comments_spec.rb