tolq-parsers-csv 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/csv/parser.rb +16 -3
- data/lib/csv/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6aa7fee3735822af2f804ba31046cac221ed33f
|
4
|
+
data.tar.gz: b3ac703861292f8434133e37506c899952d27ce7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9a80e037baa460bafaaf03fcecab858b02c18d5199ab6daec35f5c2adcd594ce49c55ef4750ab02317cb3475def9fc553f80f45f0e3d7e7aea53d54a7b20c82
|
7
|
+
data.tar.gz: c75bb72caf540dfbcf4d1dea527d92e6de8022e6d11b5e10d2e9b045c3089f4856ca2ba7dac8821a9b7f42d0f0b52a0892dcc1df8de2a4bbc3891da9032ed68d
|
data/lib/csv/parser.rb
CHANGED
@@ -13,10 +13,10 @@ module Tolq::Parsers::CSV
|
|
13
13
|
def self.to_hash(csv_io, **parse_opts)
|
14
14
|
rdata = {}
|
15
15
|
begin
|
16
|
-
CSV.new(csv_io, parse_opts).each.with_index do |row, rowidx|
|
16
|
+
CSV.new(csv_io, parse_opts.merge(self.default_options)).each.with_index do |row, rowidx|
|
17
17
|
row.each.with_index do |col, colidx|
|
18
18
|
charcol = ColumnHelper.column_to_char(colidx)
|
19
|
-
rdata["#{charcol}#{rowidx + 1}"] = col if col && col.length > 0
|
19
|
+
rdata["#{charcol}#{rowidx + 1}"] = fix_escaped_quotes(col) if col && col.length > 0
|
20
20
|
end
|
21
21
|
end
|
22
22
|
rescue CSV::MalformedCSVError => e
|
@@ -59,6 +59,19 @@ module Tolq::Parsers::CSV
|
|
59
59
|
|
60
60
|
private
|
61
61
|
|
62
|
+
def self.default_options
|
63
|
+
major, minor, patch = RUBY_VERSION.split(".").map(&:to_i)
|
64
|
+
if major >= 2 && minor >= 4
|
65
|
+
{ liberal_parsing: true }
|
66
|
+
else
|
67
|
+
{}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.fix_escaped_quotes(col)
|
72
|
+
col.gsub(/(?<!\\)\\"/,'""')
|
73
|
+
end
|
74
|
+
|
62
75
|
def extract_request_data_from_csv(csv_text, parse_opts)
|
63
76
|
rdata = {}
|
64
77
|
begin
|
@@ -66,7 +79,7 @@ module Tolq::Parsers::CSV
|
|
66
79
|
row.each.with_index do |col, colidx|
|
67
80
|
next if excluded?(colidx, rowidx)
|
68
81
|
charcol = ColumnHelper.column_to_char(colidx)
|
69
|
-
rdata["#{charcol}#{rowidx + 1}"] = { "text" => col } if col && col.length > 0
|
82
|
+
rdata["#{charcol}#{rowidx + 1}"] = { "text" => self.class.fix_escaped_quotes(col) } if col && col.length > 0
|
70
83
|
end
|
71
84
|
end
|
72
85
|
rescue CSV::MalformedCSVError => e
|
data/lib/csv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tolq-parsers-csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timon Vonk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02
|
11
|
+
date: 2017-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|