smarter_csv 1.0.17 → 1.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +7 -8
- data/README.md +13 -13
- data/lib/smarter_csv/smarter_csv.rb +21 -5
- data/lib/smarter_csv/version.rb +1 -1
- data/spec/fixtures/carriage_returns_n.csv +18 -0
- data/spec/fixtures/carriage_returns_quoted.csv +3 -0
- data/spec/fixtures/carriage_returns_r.csv +1 -0
- data/spec/fixtures/carriage_returns_rn.csv +18 -0
- data/spec/fixtures/empty.csv +5 -0
- data/spec/smarter_csv/carriage_return_spec.rb +170 -0
- data/spec/smarter_csv/convert_values_to_numeric_spec.rb +3 -3
- data/spec/smarter_csv/remove_empty_values_spec.rb +13 -0
- metadata +31 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7ac58be862e87f8334e8620b317e2d4cc534b881
|
4
|
+
data.tar.gz: 91d2b6f6d80b70cfd3878e2a82abf3cb5c7e66fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 90c70c2eee91b085414aefbd0c1a59268950a2ef3d0ba4a33ec74bc7795b0712ac98e6a9f61f211774dc5c467fb6dcf0ec84c972ba587491bb480dd31915d0d7
|
7
|
+
data.tar.gz: e2688ae5b2a0f3e36e07b0e8d90847541efadb9263ccdc215b470296a078618cfd93ccd342abbcf466648f5ee5423bae5bb9bbfa69baab0157d5a426eff853bd
|
data/.travis.yml
CHANGED
@@ -5,25 +5,24 @@ rvm:
|
|
5
5
|
- 1.9.2
|
6
6
|
- 1.9.3
|
7
7
|
- 2.0.0
|
8
|
-
-
|
9
|
-
- jruby
|
8
|
+
- 2.1.3
|
9
|
+
- jruby
|
10
10
|
- ruby-head
|
11
11
|
- jruby-head
|
12
12
|
- ree
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
- rbx
|
14
|
+
# jdk:
|
15
|
+
# - oraclejdk7
|
16
|
+
# - openjdk7
|
16
17
|
env: JRUBY_OPTS="--server -Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -J-Xms512m -J-Xmx1024m"
|
17
18
|
matrix:
|
18
19
|
allow_failures:
|
19
|
-
- rbx
|
20
|
-
- rbx-19mode
|
20
|
+
- rbx
|
21
21
|
- rvm: jruby-head
|
22
22
|
- rvm: ruby-head
|
23
23
|
- rvm: ree
|
24
24
|
- rvm: 1.8.7
|
25
25
|
- rvm: jruby-18mode
|
26
|
-
- rvm: rbx-18mode
|
27
26
|
branches:
|
28
27
|
only:
|
29
28
|
- master
|
data/README.md
CHANGED
@@ -165,6 +165,15 @@ The options and the block are optional.
|
|
165
165
|
| :verbose | false | print out line number while processing (to track down problems in input files) |
|
166
166
|
|
167
167
|
|
168
|
+
#### NOTES about File Encodings:
|
169
|
+
* if you have a CSV file which contains unicode characters, you can process it as follows:
|
170
|
+
|
171
|
+
|
172
|
+
f = File.open(filename, "r:bom|utf-8");
|
173
|
+
data = SmarterCSV.process(f);
|
174
|
+
f.close
|
175
|
+
|
176
|
+
|
168
177
|
#### NOTES about CSV Headers:
|
169
178
|
* as this method parses CSV files, it is assumed that the first line of any file will contain a valid header
|
170
179
|
* the first line with the CSV header may or may not be commented out according to the :comment_regexp
|
@@ -191,19 +200,6 @@ The options and the block are optional.
|
|
191
200
|
|
192
201
|
#### Known Issues:
|
193
202
|
* if you are using 1.8.7 versions of Ruby, JRuby, or Ruby Enterprise Edition, `smarter_csv` will have problems with double-quoted fields, because of a bug in an underlying library.
|
194
|
-
* if your CSV data contains the :row_sep character, e.g. CR, smarter_csv will not be able to handle the data, but will report `CSV::MalformedCSVError: Unclosed quoted field`.
|
195
|
-
|
196
|
-
|
197
|
-
Example of Invalid CSV:
|
198
|
-
|
199
|
-
id,name,comment
|
200
|
-
1,James,a simple comment
|
201
|
-
2,Paul,"a comment which contains
|
202
|
-
the :row_sep character CR"
|
203
|
-
3,Frank,"some other comment"
|
204
|
-
|
205
|
-
The second row contains a comment with an embedded \n carriage return character.
|
206
|
-
`smarter_csv` handles this special case as invalid CSV.
|
207
203
|
|
208
204
|
|
209
205
|
## See also:
|
@@ -229,6 +225,9 @@ Or install it yourself as:
|
|
229
225
|
|
230
226
|
## Changes
|
231
227
|
|
228
|
+
#### 1.0.18 (2014-10-27)
|
229
|
+
* added support for multi-line fields / csv fields containing CR (thanks to Chris Hilton) (issue #31)
|
230
|
+
|
232
231
|
#### 1.0.17 (2014-01-13)
|
233
232
|
* added option to set :row_sep to :auto , for automatic detection of the row-separator (issue #22)
|
234
233
|
|
@@ -327,6 +326,7 @@ Please [open an Issue on GitHub](https://github.com/tilo/smarter_csv/issues) if
|
|
327
326
|
Many thanks to people who have filed issues and sent comments.
|
328
327
|
And a special thanks to those who contributed pull requests:
|
329
328
|
|
329
|
+
* [Chris Hilton](https://github.com/chrismhilton)
|
330
330
|
* [Sean Duckett](http://github.com/sduckett)
|
331
331
|
* [Alex Ong](http://github.com/khaong)
|
332
332
|
* [Martin Nilsson](http://github.com/MrTin)
|
@@ -21,7 +21,7 @@ module SmarterCSV
|
|
21
21
|
f = input.respond_to?(:readline) ? input : File.open(input, "r:#{options[:file_encoding]}")
|
22
22
|
|
23
23
|
if options[:row_sep] == :auto
|
24
|
-
options[:row_sep] = SmarterCSV.guess_line_ending( f )
|
24
|
+
options[:row_sep] = SmarterCSV.guess_line_ending( f, options )
|
25
25
|
f.rewind
|
26
26
|
end
|
27
27
|
$/ = options[:row_sep]
|
@@ -87,6 +87,15 @@ module SmarterCSV
|
|
87
87
|
line_count += 1
|
88
88
|
print "processing line %10d\r" % line_count if options[:verbose]
|
89
89
|
next if line =~ options[:comment_regexp] # ignore all comment lines if there are any
|
90
|
+
|
91
|
+
# cater for the quoted csv data containing the row separator carriage return character
|
92
|
+
# in which case the row data will be split across multiple lines (see the sample content in spec/fixtures/carriage_returns_rn.csv)
|
93
|
+
# by detecting the existence of an uneven number of quote characters
|
94
|
+
while line.count(options[:quote_char])%2 == 1
|
95
|
+
print "line contains uneven number of quote chars so including content of next line" if options[:verbose]
|
96
|
+
line += f.readline
|
97
|
+
end
|
98
|
+
|
90
99
|
line.chomp! # will use $/ which is set to options[:col_sep]
|
91
100
|
|
92
101
|
if (line =~ %r{#{options[:quote_char]}}) and (! options[:force_simple_split])
|
@@ -104,7 +113,10 @@ module SmarterCSV
|
|
104
113
|
eval('hash.delete(:"")')
|
105
114
|
end
|
106
115
|
|
107
|
-
|
116
|
+
# remove empty values using the same regexp as used by the rails blank? method
|
117
|
+
# which caters for double \n and \r\n characters such as "1\r\n\r\n2" whereas the original check (v =~ /^\s*$/) does not
|
118
|
+
hash.delete_if{|k,v| v.nil? || v !~ /[^[:space:]]/} if options[:remove_empty_values]
|
119
|
+
|
108
120
|
hash.delete_if{|k,v| ! v.nil? && v =~ /^(\d+|\d+\.\d+)$/ && v.to_f == 0} if options[:remove_zero_values] # values are typically Strings!
|
109
121
|
hash.delete_if{|k,v| v =~ options[:remove_values_matching]} if options[:remove_values_matching]
|
110
122
|
if options[:convert_values_to_numeric]
|
@@ -192,12 +204,16 @@ module SmarterCSV
|
|
192
204
|
end
|
193
205
|
|
194
206
|
# limitation: this currently reads the whole file in before making a decision
|
195
|
-
def self.guess_line_ending( filehandle )
|
207
|
+
def self.guess_line_ending( filehandle, options )
|
196
208
|
counts = {"\n" => 0 , "\r" => 0, "\r\n" => 0}
|
209
|
+
quoted_char = false
|
197
210
|
|
211
|
+
# count how many of the pre-defined line-endings we find
|
212
|
+
# ignoring those contained within quote characters
|
198
213
|
filehandle.each_char do |c|
|
199
|
-
|
200
|
-
|
214
|
+
quoted_char = !quoted_char if c == options[:quote_char]
|
215
|
+
next if quoted_char || c !~ /\r|\n|\r\n/
|
216
|
+
counts[c] += 1
|
201
217
|
end
|
202
218
|
# find the key/value pair with the largest counter:
|
203
219
|
k,v = counts.max_by{|k,v| v}
|
data/lib/smarter_csv/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
Name,Street,City
|
2
|
+
Anfield,Anfield Road,Liverpool
|
3
|
+
"Highbury
|
4
|
+
Highbury House",75 Drayton Park,London
|
5
|
+
Old Trafford,"Sir Matt
|
6
|
+
Busby Way",Manchester
|
7
|
+
St. James' Park,,"Newcastle-upon-tyne
|
8
|
+
Tyne and Wear"
|
9
|
+
"White Hart Lane
|
10
|
+
(The Lane)","Bill Nicholson Way
|
11
|
+
748 High Rd","Tottenham
|
12
|
+
London"
|
13
|
+
Stamford Bridge,"Fulham Road
|
14
|
+
London",
|
15
|
+
"Etihad Stadium
|
16
|
+
Rowsley St
|
17
|
+
Manchester",,
|
18
|
+
Goodison,Goodison Road,Liverpool
|
@@ -0,0 +1 @@
|
|
1
|
+
Name,Street,City
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Name,Street,City
|
2
|
+
Anfield,Anfield Road,Liverpool
|
3
|
+
"Highbury
|
4
|
+
Highbury House",75 Drayton Park,London
|
5
|
+
Old Trafford,"Sir Matt
|
6
|
+
Busby Way",Manchester
|
7
|
+
St. James' Park,,"Newcastle-upon-tyne
|
8
|
+
Tyne and Wear"
|
9
|
+
"White Hart Lane
|
10
|
+
(The Lane)","Bill Nicholson Way
|
11
|
+
748 High Rd","Tottenham
|
12
|
+
London"
|
13
|
+
Stamford Bridge,"Fulham Road
|
14
|
+
London",
|
15
|
+
"Etihad Stadium
|
16
|
+
Rowsley St
|
17
|
+
Manchester",,
|
18
|
+
Goodison,Goodison Road,Liverpool
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
fixture_path = 'spec/fixtures'
|
4
|
+
|
5
|
+
describe 'process files with line endings explicitly pre-specified' do
|
6
|
+
|
7
|
+
it 'should process a file with \n for line endings and within data fields' do
|
8
|
+
sep = "\n"
|
9
|
+
options = {:row_sep => sep}
|
10
|
+
data = SmarterCSV.process("#{fixture_path}/carriage_returns_n.csv", {:row_sep => sep})
|
11
|
+
data.flatten.size.should == 8
|
12
|
+
data[0][:name].should == "Anfield"
|
13
|
+
data[0][:street].should == "Anfield Road"
|
14
|
+
data[0][:city].should == "Liverpool"
|
15
|
+
data[1][:name].should == ["Highbury", "Highbury House"].join(sep)
|
16
|
+
data[2][:street].should == ["Sir Matt ", "Busby Way"].join(sep)
|
17
|
+
data[3][:city].should == ["Newcastle-upon-tyne ", "Tyne and Wear"].join(sep)
|
18
|
+
data[4][:name].should == ["White Hart Lane", "(The Lane)"].join(sep)
|
19
|
+
data[4][:street].should == ["Bill Nicholson Way ", "748 High Rd"].join(sep)
|
20
|
+
data[4][:city].should == ["Tottenham", "London"].join(sep)
|
21
|
+
data[5][:name].should == "Stamford Bridge"
|
22
|
+
data[5][:street].should == ["Fulham Road", "London"].join(sep)
|
23
|
+
data[5][:city].should be_nil
|
24
|
+
data[6][:name].should == ["Etihad Stadium", "Rowsley St", "Manchester"].join(sep)
|
25
|
+
data[7][:name].should == "Goodison"
|
26
|
+
data[7][:street].should == "Goodison Road"
|
27
|
+
data[7][:city].should == "Liverpool"
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should process a file with \r for line endings and within data fields' do
|
31
|
+
sep = "\r"
|
32
|
+
data = SmarterCSV.process("#{fixture_path}/carriage_returns_r.csv", {:row_sep => sep})
|
33
|
+
data.flatten.size.should == 8
|
34
|
+
data[0][:name].should == "Anfield"
|
35
|
+
data[0][:street].should == "Anfield Road"
|
36
|
+
data[0][:city].should == "Liverpool"
|
37
|
+
data[1][:name].should == ["Highbury", "Highbury House"].join(sep)
|
38
|
+
data[2][:street].should == ["Sir Matt ", "Busby Way"].join(sep)
|
39
|
+
data[3][:city].should == ["Newcastle-upon-tyne ", "Tyne and Wear"].join(sep)
|
40
|
+
data[4][:name].should == ["White Hart Lane", "(The Lane)"].join(sep)
|
41
|
+
data[4][:street].should == ["Bill Nicholson Way ", "748 High Rd"].join(sep)
|
42
|
+
data[4][:city].should == ["Tottenham", "London"].join(sep)
|
43
|
+
data[5][:name].should == "Stamford Bridge"
|
44
|
+
data[5][:street].should == ["Fulham Road", "London"].join(sep)
|
45
|
+
data[5][:city].should be_nil
|
46
|
+
data[6][:name].should == ["Etihad Stadium", "Rowsley St", "Manchester"].join(sep)
|
47
|
+
data[7][:name].should == "Goodison"
|
48
|
+
data[7][:street].should == "Goodison Road"
|
49
|
+
data[7][:city].should == "Liverpool"
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should process a file with \r\n for line endings and within data fields' do
|
53
|
+
sep = "\r\n"
|
54
|
+
data = SmarterCSV.process("#{fixture_path}/carriage_returns_rn.csv", {:row_sep => sep})
|
55
|
+
data.flatten.size.should == 8
|
56
|
+
data[0][:name].should == "Anfield"
|
57
|
+
data[0][:street].should == "Anfield Road"
|
58
|
+
data[0][:city].should == "Liverpool"
|
59
|
+
data[1][:name].should == ["Highbury", "Highbury House"].join(sep)
|
60
|
+
data[2][:street].should == ["Sir Matt ", "Busby Way"].join(sep)
|
61
|
+
data[3][:city].should == ["Newcastle-upon-tyne ", "Tyne and Wear"].join(sep)
|
62
|
+
data[4][:name].should == ["White Hart Lane", "(The Lane)"].join(sep)
|
63
|
+
data[4][:street].should == ["Bill Nicholson Way ", "748 High Rd"].join(sep)
|
64
|
+
data[4][:city].should == ["Tottenham", "London"].join(sep)
|
65
|
+
data[5][:name].should == "Stamford Bridge"
|
66
|
+
data[5][:street].should == ["Fulham Road", "London"].join(sep)
|
67
|
+
data[5][:city].should be_nil
|
68
|
+
data[6][:name].should == ["Etihad Stadium", "Rowsley St", "Manchester"].join(sep)
|
69
|
+
data[7][:name].should == "Goodison"
|
70
|
+
data[7][:street].should == "Goodison Road"
|
71
|
+
data[7][:city].should == "Liverpool"
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should process a file with more quoted text carriage return characters (\r) than line ending characters (\n)' do
|
75
|
+
row_sep = "\n"
|
76
|
+
text_sep = "\r"
|
77
|
+
data = SmarterCSV.process("#{fixture_path}/carriage_returns_quoted.csv", {:row_sep => row_sep})
|
78
|
+
data.flatten.size.should == 2
|
79
|
+
data[0][:band].should == "New Order"
|
80
|
+
data[0][:members].should == ["Bernard Sumner", "Peter Hook", "Stephen Morris", "Gillian Gilbert"].join(text_sep)
|
81
|
+
data[0][:albums].should == ["Movement", "Power, Corruption and Lies", "Low-Life", "Brotherhood", "Substance"].join(text_sep)
|
82
|
+
data[1][:band].should == "Led Zeppelin"
|
83
|
+
data[1][:members].should == ["Jimmy Page", "Robert Plant", "John Bonham", "John Paul Jones"].join(text_sep)
|
84
|
+
data[1][:albums].should == ["Led Zeppelin", "Led Zeppelin II", "Led Zeppelin III", "Led Zeppelin IV"].join(text_sep)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'process files with line endings in automatic mode' do
|
90
|
+
|
91
|
+
it 'should process a file with \n for line endings and within data fields' do
|
92
|
+
sep = "\n"
|
93
|
+
data = SmarterCSV.process("#{fixture_path}/carriage_returns_n.csv", {:row_sep => :auto})
|
94
|
+
data.flatten.size.should == 8
|
95
|
+
data[0][:name].should == "Anfield"
|
96
|
+
data[0][:street].should == "Anfield Road"
|
97
|
+
data[0][:city].should == "Liverpool"
|
98
|
+
data[1][:name].should == ["Highbury", "Highbury House"].join(sep)
|
99
|
+
data[2][:street].should == ["Sir Matt ", "Busby Way"].join(sep)
|
100
|
+
data[3][:city].should == ["Newcastle-upon-tyne ", "Tyne and Wear"].join(sep)
|
101
|
+
data[4][:name].should == ["White Hart Lane", "(The Lane)"].join(sep)
|
102
|
+
data[4][:street].should == ["Bill Nicholson Way ", "748 High Rd"].join(sep)
|
103
|
+
data[4][:city].should == ["Tottenham", "London"].join(sep)
|
104
|
+
data[5][:name].should == "Stamford Bridge"
|
105
|
+
data[5][:street].should == ["Fulham Road", "London"].join(sep)
|
106
|
+
data[5][:city].should be_nil
|
107
|
+
data[6][:name].should == ["Etihad Stadium", "Rowsley St", "Manchester"].join(sep)
|
108
|
+
data[7][:name].should == "Goodison"
|
109
|
+
data[7][:street].should == "Goodison Road"
|
110
|
+
data[7][:city].should == "Liverpool"
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should process a file with \r for line endings and within data fields' do
|
114
|
+
sep = "\r"
|
115
|
+
data = SmarterCSV.process("#{fixture_path}/carriage_returns_r.csv", {:row_sep => :auto})
|
116
|
+
data.flatten.size.should == 8
|
117
|
+
data[0][:name].should == "Anfield"
|
118
|
+
data[0][:street].should == "Anfield Road"
|
119
|
+
data[0][:city].should == "Liverpool"
|
120
|
+
data[1][:name].should == ["Highbury", "Highbury House"].join(sep)
|
121
|
+
data[2][:street].should == ["Sir Matt ", "Busby Way"].join(sep)
|
122
|
+
data[3][:city].should == ["Newcastle-upon-tyne ", "Tyne and Wear"].join(sep)
|
123
|
+
data[4][:name].should == ["White Hart Lane", "(The Lane)"].join(sep)
|
124
|
+
data[4][:street].should == ["Bill Nicholson Way ", "748 High Rd"].join(sep)
|
125
|
+
data[4][:city].should == ["Tottenham", "London"].join(sep)
|
126
|
+
data[5][:name].should == "Stamford Bridge"
|
127
|
+
data[5][:street].should == ["Fulham Road", "London"].join(sep)
|
128
|
+
data[5][:city].should be_nil
|
129
|
+
data[6][:name].should == ["Etihad Stadium", "Rowsley St", "Manchester"].join(sep)
|
130
|
+
data[7][:name].should == "Goodison"
|
131
|
+
data[7][:street].should == "Goodison Road"
|
132
|
+
data[7][:city].should == "Liverpool"
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should process a file with \r\n for line endings and within data fields' do
|
136
|
+
sep = "\r\n"
|
137
|
+
data = SmarterCSV.process("#{fixture_path}/carriage_returns_rn.csv", {:row_sep => :auto})
|
138
|
+
data.flatten.size.should == 8
|
139
|
+
data[0][:name].should == "Anfield"
|
140
|
+
data[0][:street].should == "Anfield Road"
|
141
|
+
data[0][:city].should == "Liverpool"
|
142
|
+
data[1][:name].should == ["Highbury", "Highbury House"].join(sep)
|
143
|
+
data[2][:street].should == ["Sir Matt ", "Busby Way"].join(sep)
|
144
|
+
data[3][:city].should == ["Newcastle-upon-tyne ", "Tyne and Wear"].join(sep)
|
145
|
+
data[4][:name].should == ["White Hart Lane", "(The Lane)"].join(sep)
|
146
|
+
data[4][:street].should == ["Bill Nicholson Way ", "748 High Rd"].join(sep)
|
147
|
+
data[4][:city].should == ["Tottenham", "London"].join(sep)
|
148
|
+
data[5][:name].should == "Stamford Bridge"
|
149
|
+
data[5][:street].should == ["Fulham Road", "London"].join(sep)
|
150
|
+
data[5][:city].should be_nil
|
151
|
+
data[6][:name].should == ["Etihad Stadium", "Rowsley St", "Manchester"].join(sep)
|
152
|
+
data[7][:name].should == "Goodison"
|
153
|
+
data[7][:street].should == "Goodison Road"
|
154
|
+
data[7][:city].should == "Liverpool"
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should process a file with more quoted text carriage return characters (\r) than line ending characters (\n)' do
|
158
|
+
row_sep = "\n"
|
159
|
+
text_sep = "\r"
|
160
|
+
data = SmarterCSV.process("#{fixture_path}/carriage_returns_quoted.csv", {:row_sep => :auto})
|
161
|
+
data.flatten.size.should == 2
|
162
|
+
data[0][:band].should == "New Order"
|
163
|
+
data[0][:members].should == ["Bernard Sumner", "Peter Hook", "Stephen Morris", "Gillian Gilbert"].join(text_sep)
|
164
|
+
data[0][:albums].should == ["Movement", "Power, Corruption and Lies", "Low-Life", "Brotherhood", "Substance"].join(text_sep)
|
165
|
+
data[1][:band].should == "Led Zeppelin"
|
166
|
+
data[1][:members].should == ["Jimmy Page", "Robert Plant", "John Bonham", "John Paul Jones"].join(text_sep)
|
167
|
+
data[1][:albums].should == ["Led Zeppelin", "Led Zeppelin II", "Led Zeppelin III", "Led Zeppelin IV"].join(text_sep)
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
@@ -16,7 +16,7 @@ describe 'numeric conversion of values' do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'can be prevented for all values' do
|
19
|
-
options = { convert_values_to_numeric
|
19
|
+
options = { :convert_values_to_numeric => false }
|
20
20
|
data = SmarterCSV.process("#{fixture_path}/numeric.csv", options)
|
21
21
|
|
22
22
|
data.each do |hash|
|
@@ -26,7 +26,7 @@ describe 'numeric conversion of values' do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'can be prevented for some keys' do
|
29
|
-
options = { convert_values_to_numeric
|
29
|
+
options = { :convert_values_to_numeric => { :except => :reference }}
|
30
30
|
data = SmarterCSV.process("#{fixture_path}/numeric.csv", options)
|
31
31
|
|
32
32
|
data.each do |hash|
|
@@ -36,7 +36,7 @@ describe 'numeric conversion of values' do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'can occur only for some keys' do
|
39
|
-
options = { convert_values_to_numeric
|
39
|
+
options = { :convert_values_to_numeric => { :only => :wealth }}
|
40
40
|
data = SmarterCSV.process("#{fixture_path}/numeric.csv", options)
|
41
41
|
|
42
42
|
data.each do |hash|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
fixture_path = 'spec/fixtures'
|
4
|
+
|
5
|
+
describe 'be_able_to' do
|
6
|
+
it 'remove_empty_values' do
|
7
|
+
options = {:row_sep => :auto, :remove_empty_values => true}
|
8
|
+
data = SmarterCSV.process("#{fixture_path}/empty.csv", options)
|
9
|
+
data.size.should == 1
|
10
|
+
data[0].keys.should == [:not_empty_1, :not_empty_2, :not_empty_3]
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
metadata
CHANGED
@@ -1,49 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smarter_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.18
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
|
-
-
|
9
|
-
|
10
|
-
'
|
7
|
+
- |
|
8
|
+
Tilo Sloboda
|
11
9
|
autorequire:
|
12
10
|
bindir: bin
|
13
11
|
cert_chain: []
|
14
|
-
date: 2014-
|
12
|
+
date: 2014-10-28 00:00:00.000000000 Z
|
15
13
|
dependencies:
|
16
14
|
- !ruby/object:Gem::Dependency
|
17
15
|
name: rspec
|
18
16
|
requirement: !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
17
|
requirements:
|
21
|
-
- -
|
18
|
+
- - ">="
|
22
19
|
- !ruby/object:Gem::Version
|
23
20
|
version: '0'
|
24
21
|
type: :development
|
25
22
|
prerelease: false
|
26
23
|
version_requirements: !ruby/object:Gem::Requirement
|
27
|
-
none: false
|
28
24
|
requirements:
|
29
|
-
- -
|
25
|
+
- - ">="
|
30
26
|
- !ruby/object:Gem::Version
|
31
27
|
version: '0'
|
32
28
|
description: Ruby Gem for smarter importing of CSV Files as Array(s) of Hashes, with
|
33
29
|
optional features for processing large files in parallel, embedded comments, unusual
|
34
30
|
field- and record-separators, flexible mapping of CSV-headers to Hash-keys
|
35
31
|
email:
|
36
|
-
-
|
37
|
-
|
38
|
-
'
|
32
|
+
- |
|
33
|
+
tilo.sloboda@gmail.com
|
39
34
|
executables: []
|
40
35
|
extensions: []
|
41
36
|
extra_rdoc_files: []
|
42
37
|
files:
|
43
|
-
- .gitignore
|
44
|
-
- .rspec
|
45
|
-
- .rvmrc
|
46
|
-
- .travis.yml
|
38
|
+
- ".gitignore"
|
39
|
+
- ".rspec"
|
40
|
+
- ".rvmrc"
|
41
|
+
- ".travis.yml"
|
47
42
|
- Gemfile
|
48
43
|
- README.md
|
49
44
|
- Rakefile
|
@@ -54,7 +49,12 @@ files:
|
|
54
49
|
- smarter_csv.gemspec
|
55
50
|
- spec/fixtures/basic.csv
|
56
51
|
- spec/fixtures/binary.csv
|
52
|
+
- spec/fixtures/carriage_returns_n.csv
|
53
|
+
- spec/fixtures/carriage_returns_quoted.csv
|
54
|
+
- spec/fixtures/carriage_returns_r.csv
|
55
|
+
- spec/fixtures/carriage_returns_rn.csv
|
57
56
|
- spec/fixtures/chunk_cornercase.csv
|
57
|
+
- spec/fixtures/empty.csv
|
58
58
|
- spec/fixtures/line_endings_n.csv
|
59
59
|
- spec/fixtures/line_endings_r.csv
|
60
60
|
- spec/fixtures/line_endings_rn.csv
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- spec/fixtures/separator.csv
|
67
67
|
- spec/smarter_csv/binary_file2_spec.rb
|
68
68
|
- spec/smarter_csv/binary_file_spec.rb
|
69
|
+
- spec/smarter_csv/carriage_return_spec.rb
|
69
70
|
- spec/smarter_csv/chunked_reading_spec.rb
|
70
71
|
- spec/smarter_csv/column_separator_spec.rb
|
71
72
|
- spec/smarter_csv/convert_values_to_numeric_spec.rb
|
@@ -75,6 +76,7 @@ files:
|
|
75
76
|
- spec/smarter_csv/no_header_spec.rb
|
76
77
|
- spec/smarter_csv/not_downcase_header_spec.rb
|
77
78
|
- spec/smarter_csv/quoted_spec.rb
|
79
|
+
- spec/smarter_csv/remove_empty_values_spec.rb
|
78
80
|
- spec/smarter_csv/remove_keys_from_hashes_spec.rb
|
79
81
|
- spec/smarter_csv/remove_not_mapped_keys_spec.rb
|
80
82
|
- spec/smarter_csv/remove_values_matching_spec.rb
|
@@ -88,34 +90,38 @@ homepage: https://github.com/tilo/smarter_csv
|
|
88
90
|
licenses:
|
89
91
|
- MIT
|
90
92
|
- GPL-2
|
93
|
+
metadata: {}
|
91
94
|
post_install_message:
|
92
95
|
rdoc_options: []
|
93
96
|
require_paths:
|
94
97
|
- lib
|
95
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
99
|
requirements:
|
98
|
-
- -
|
100
|
+
- - ">="
|
99
101
|
- !ruby/object:Gem::Version
|
100
102
|
version: '0'
|
101
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
-
none: false
|
103
104
|
requirements:
|
104
|
-
- -
|
105
|
+
- - ">="
|
105
106
|
- !ruby/object:Gem::Version
|
106
107
|
version: '0'
|
107
108
|
requirements:
|
108
109
|
- csv
|
109
110
|
rubyforge_project:
|
110
|
-
rubygems_version:
|
111
|
+
rubygems_version: 2.2.2
|
111
112
|
signing_key:
|
112
|
-
specification_version:
|
113
|
+
specification_version: 4
|
113
114
|
summary: Ruby Gem for smarter importing of CSV Files (and CSV-like files), with lots
|
114
115
|
of optional features, e.g. chunked processing for huge CSV files
|
115
116
|
test_files:
|
116
117
|
- spec/fixtures/basic.csv
|
117
118
|
- spec/fixtures/binary.csv
|
119
|
+
- spec/fixtures/carriage_returns_n.csv
|
120
|
+
- spec/fixtures/carriage_returns_quoted.csv
|
121
|
+
- spec/fixtures/carriage_returns_r.csv
|
122
|
+
- spec/fixtures/carriage_returns_rn.csv
|
118
123
|
- spec/fixtures/chunk_cornercase.csv
|
124
|
+
- spec/fixtures/empty.csv
|
119
125
|
- spec/fixtures/line_endings_n.csv
|
120
126
|
- spec/fixtures/line_endings_r.csv
|
121
127
|
- spec/fixtures/line_endings_rn.csv
|
@@ -127,6 +133,7 @@ test_files:
|
|
127
133
|
- spec/fixtures/separator.csv
|
128
134
|
- spec/smarter_csv/binary_file2_spec.rb
|
129
135
|
- spec/smarter_csv/binary_file_spec.rb
|
136
|
+
- spec/smarter_csv/carriage_return_spec.rb
|
130
137
|
- spec/smarter_csv/chunked_reading_spec.rb
|
131
138
|
- spec/smarter_csv/column_separator_spec.rb
|
132
139
|
- spec/smarter_csv/convert_values_to_numeric_spec.rb
|
@@ -136,6 +143,7 @@ test_files:
|
|
136
143
|
- spec/smarter_csv/no_header_spec.rb
|
137
144
|
- spec/smarter_csv/not_downcase_header_spec.rb
|
138
145
|
- spec/smarter_csv/quoted_spec.rb
|
146
|
+
- spec/smarter_csv/remove_empty_values_spec.rb
|
139
147
|
- spec/smarter_csv/remove_keys_from_hashes_spec.rb
|
140
148
|
- spec/smarter_csv/remove_not_mapped_keys_spec.rb
|
141
149
|
- spec/smarter_csv/remove_values_matching_spec.rb
|