smarter_csv 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/README.md +3 -5
- data/lib/smarter_csv/smarter_csv.rb +8 -1
- data/lib/smarter_csv/version.rb +1 -1
- data/spec/fixtures/problematic.csv +8 -0
- data/spec/smarter_csv/problematic.rb +34 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b12b00d4615d3c9c6bb3f233b5179b8a3990204af46c88b6ee2203de307608e0
|
4
|
+
data.tar.gz: 215dc43d5280083f7452c0be169daab991057239601fa37c23cd474649a8cd4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05bc8348e29d095788ee6d2a9cf299232fc1e7f8abc5048544e80a0f0c6b5d7517b935daddc3eb697a5f01616eb5a3dd2a9b4d0ee489f358e0b95718caba243f
|
7
|
+
data.tar.gz: bd2b070f965ba554b2b2551a5959690308a1a68fdbe452b6d7900e7c665202e73e1b1bfba0b4d4da72324490c55e8fd869497df64e959b80706af63509a4b1fd
|
data/.travis.yml
CHANGED
@@ -9,7 +9,7 @@ matrix:
|
|
9
9
|
- rvm: 2.2.8
|
10
10
|
- rvm: 2.3.5
|
11
11
|
- rvm: 2.4.2
|
12
|
-
- rvm: jruby-9.1.
|
12
|
+
- rvm: jruby-9.1.15.0
|
13
13
|
env:
|
14
14
|
- JRUBY_OPTS="--server -Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -J-Xms512m -J-Xmx1024m"
|
15
15
|
- rvm: ruby-head
|
@@ -17,3 +17,5 @@ matrix:
|
|
17
17
|
branches:
|
18
18
|
only:
|
19
19
|
- master
|
20
|
+
- 1.2-stable
|
21
|
+
- 2.0-develop
|
data/README.md
CHANGED
@@ -324,11 +324,12 @@ Planned in the next releases:
|
|
324
324
|
|
325
325
|
## Changes
|
326
326
|
|
327
|
+
#### 1.2.4 (2018-08-06)
|
328
|
+
* using Rails blank? if it's available
|
329
|
+
|
327
330
|
#### 1.2.3 (2018-01-27)
|
328
331
|
* fixed regression / test
|
329
332
|
* fuxed quote_char interpolation for headers, but not data (thanks to Colin Petruno)
|
330
|
-
|
331
|
-
#### 1.2.1 (2018-01-25) ### YANKED!
|
332
333
|
* bugfix (thanks to Joshua Smith for reporting)
|
333
334
|
|
334
335
|
#### 1.2.0 (2018-01-20)
|
@@ -385,9 +386,6 @@ Planned in the next releases:
|
|
385
386
|
#### 1.0.14 (2013-11-01)
|
386
387
|
* added GPL-2 and MIT license to GEM spec file; if you need another license contact me
|
387
388
|
|
388
|
-
#### 1.0.13 (2013-11-01) ### YANKED!
|
389
|
-
* added GPL-2 license to GEM spec file; if you need another license contact me
|
390
|
-
|
391
389
|
#### 1.0.12 (2013-10-15)
|
392
390
|
* added RSpec tests
|
393
391
|
|
@@ -22,6 +22,7 @@ module SmarterCSV
|
|
22
22
|
old_row_sep = $/
|
23
23
|
file_line_count = 0
|
24
24
|
csv_line_count = 0
|
25
|
+
has_rails = !! defined?(Rails)
|
25
26
|
begin
|
26
27
|
f = input.respond_to?(:readline) ? input : File.open(input, "r:#{options[:file_encoding]}")
|
27
28
|
|
@@ -167,7 +168,13 @@ module SmarterCSV
|
|
167
168
|
|
168
169
|
# remove empty values using the same regexp as used by the rails blank? method
|
169
170
|
# which caters for double \n and \r\n characters such as "1\r\n\r\n2" whereas the original check (v =~ /^\s*$/) does not
|
170
|
-
|
171
|
+
if options[:remove_empty_values]
|
172
|
+
if has_rails
|
173
|
+
hash.delete_if{|k,v| v.blank?}
|
174
|
+
else
|
175
|
+
hash.delete_if{|k,v| v.nil? || v !~ /[^[:space:]]/}
|
176
|
+
end
|
177
|
+
end
|
171
178
|
|
172
179
|
hash.delete_if{|k,v| ! v.nil? && v =~ /^(\d+|\d+\.\d+)$/ && v.to_f == 0} if options[:remove_zero_values] # values are typically Strings!
|
173
180
|
hash.delete_if{|k,v| v =~ options[:remove_values_matching]} if options[:remove_values_matching]
|
data/lib/smarter_csv/version.rb
CHANGED
@@ -0,0 +1,8 @@
|
|
1
|
+
Compte;Date de comptabilisation;Date op�ration;Libell�;R�f�rence;Date valeur;Montant
|
2
|
+
22215449203;02/06/2018;01/06/2018;ECHEANCE PRET DONT CAP 410,33 ASS. 8,00E INT. 21,87 COM. 0,00E;8711552;01/06/2018;-440,20;
|
3
|
+
22215449203;04/06/2018;04/06/2018;EVI Gaultier Laperche remboursement compte courant;1038326;04/06/2018;-144,07;
|
4
|
+
22215449203;04/06/2018;04/06/2018;EVI Guillemain Nicolas remboursement CC pret d'honneur;1038328;04/06/2018;-144,07;
|
5
|
+
22215449203;01/06/2018;01/06/2018;310518 SC****5448 INTERMARCHE 95ERMONT;701JQ1K;01/06/2018;-16,00;
|
6
|
+
22215449203;01/06/2018;01/06/2018;EVI Stripe Payments UK L STRIPE E7U0R1;706AO1Q;01/06/2018;45,89;
|
7
|
+
22215449203;01/06/2018;01/06/2018;EVI Compte N26 Heroku;1100653;01/06/2018;-700,00;
|
8
|
+
22215449203;31/05/2018;31/05/2018;EVI Stripe Payments UK L STRIPE L2J1N7;6YISBWF;31/05/2018;465,89;
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
fixture_path = 'spec/fixtures'
|
4
|
+
|
5
|
+
describe 'loading file with UTF-8 characters in the header' do
|
6
|
+
|
7
|
+
# file which caused issues because of UTF-8 characters in the header
|
8
|
+
it 'loads the file with force_utf8 flag set' do
|
9
|
+
options = {col_sep: ";", force_utf8: true}
|
10
|
+
data = SmarterCSV.process("#{fixture_path}/problematic.csv", options)
|
11
|
+
|
12
|
+
data.length.should eq 7
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'loads the file with strings as keys' do
|
16
|
+
options = {
|
17
|
+
file_encoding: 'iso-8859-1:UTF-8', # important!
|
18
|
+
col_sep: ";", strings_as_keys: true,
|
19
|
+
}
|
20
|
+
data = SmarterCSV.process("#{fixture_path}/problematic.csv", options)
|
21
|
+
|
22
|
+
data.length.should eq 7
|
23
|
+
data.first.keys.sort.should eq [
|
24
|
+
"compte",
|
25
|
+
"date_de_comptabilisation",
|
26
|
+
"date_opération",
|
27
|
+
"date_valeur",
|
28
|
+
"libellé",
|
29
|
+
"montant",
|
30
|
+
"référence"
|
31
|
+
]
|
32
|
+
end
|
33
|
+
|
34
|
+
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.
|
4
|
+
version: 1.2.4
|
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: 2018-
|
13
|
+
date: 2018-08-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- spec/fixtures/no_header.csv
|
69
69
|
- spec/fixtures/numeric.csv
|
70
70
|
- spec/fixtures/pets.csv
|
71
|
+
- spec/fixtures/problematic.csv
|
71
72
|
- spec/fixtures/quote_char.csv
|
72
73
|
- spec/fixtures/quoted.csv
|
73
74
|
- spec/fixtures/quoted2.csv
|
@@ -95,6 +96,7 @@ files:
|
|
95
96
|
- spec/smarter_csv/malformed_spec.rb
|
96
97
|
- spec/smarter_csv/no_header_spec.rb
|
97
98
|
- spec/smarter_csv/not_downcase_header_spec.rb
|
99
|
+
- spec/smarter_csv/problematic.rb
|
98
100
|
- spec/smarter_csv/quoted_spec.rb
|
99
101
|
- spec/smarter_csv/remove_empty_values_spec.rb
|
100
102
|
- spec/smarter_csv/remove_keys_from_hashes_spec.rb
|
@@ -157,6 +159,7 @@ test_files:
|
|
157
159
|
- spec/fixtures/no_header.csv
|
158
160
|
- spec/fixtures/numeric.csv
|
159
161
|
- spec/fixtures/pets.csv
|
162
|
+
- spec/fixtures/problematic.csv
|
160
163
|
- spec/fixtures/quote_char.csv
|
161
164
|
- spec/fixtures/quoted.csv
|
162
165
|
- spec/fixtures/quoted2.csv
|
@@ -184,6 +187,7 @@ test_files:
|
|
184
187
|
- spec/smarter_csv/malformed_spec.rb
|
185
188
|
- spec/smarter_csv/no_header_spec.rb
|
186
189
|
- spec/smarter_csv/not_downcase_header_spec.rb
|
190
|
+
- spec/smarter_csv/problematic.rb
|
187
191
|
- spec/smarter_csv/quoted_spec.rb
|
188
192
|
- spec/smarter_csv/remove_empty_values_spec.rb
|
189
193
|
- spec/smarter_csv/remove_keys_from_hashes_spec.rb
|