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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/csv/parser.rb +16 -3
  3. data/lib/csv/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29a83df2ed2eeadb5c776d96a816bdd945b554cf
4
- data.tar.gz: ab06afe8e05ad99c21242c6775ba1ec774385abd
3
+ metadata.gz: f6aa7fee3735822af2f804ba31046cac221ed33f
4
+ data.tar.gz: b3ac703861292f8434133e37506c899952d27ce7
5
5
  SHA512:
6
- metadata.gz: d7bbd4a2281da0ed35b4c2d7ba05aa55aeb198e50e0a333b13ee00058ea8da4260561fc423f73078ce886ad8091cb9d07af36b2c0c970f639d2bf3f0987e159f
7
- data.tar.gz: a952e45eccfc47a4d93135d566170f6c69f9b2ece12e5e175c7de53af39adcc4aa44824a099e683b0a8f39f2d17d45c515d7436e55707b6f3d08fda7c11ce31e
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
@@ -1,7 +1,7 @@
1
1
  module Tolq
2
2
  module Parsers
3
3
  module CSV
4
- VERSION = "0.3.2"
4
+ VERSION = "0.3.3"
5
5
  end
6
6
  end
7
7
  end
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.2
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-16 00:00:00.000000000 Z
11
+ date: 2017-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler