tolq-parsers-csv 0.2.1 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/csv/parser.rb +18 -9
- 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: 94ccec23f2b9ed6aca02230487b8f7066fb43412
|
4
|
+
data.tar.gz: 4a26a86c228b7eba43c1c915b80c7142bb1d4103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 919650c2a4c132df4c99da194ff8414dd07587c8bb197eb9347be49588b2620937102c623cd702996250482c7186bcb5f8ee8f9d97204c5f5be3a18ca143582f
|
7
|
+
data.tar.gz: 47e1cb3b4642cb89e82e8033088d7fd712299fe0a2cb161a87fa90b89d50257b4ece2c55850bb5a95a46049b83302df998b11b809d4e0297eb5791051c1a0908
|
data/lib/csv/parser.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'csv'
|
2
2
|
|
3
3
|
module Tolq::Parsers::CSV
|
4
|
+
class ParseError < StandardError; end
|
4
5
|
class Parser
|
5
6
|
|
6
7
|
# Helper method to convert a CSV into a annotated hash. Note that format
|
@@ -11,11 +12,15 @@ module Tolq::Parsers::CSV
|
|
11
12
|
# @return [Hash] Hash representation of csv, i.e. { 'A1' => 'Hello World'
|
12
13
|
def self.to_hash(csv_io, **parse_opts)
|
13
14
|
rdata = {}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
begin
|
16
|
+
CSV.new(csv_io, parse_opts).each.with_index do |row, rowidx|
|
17
|
+
row.each.with_index do |col, colidx|
|
18
|
+
charcol = ColumnHelper.column_to_char(colidx)
|
19
|
+
rdata["#{charcol}#{rowidx + 1}"] = col if col && col.length > 0
|
20
|
+
end
|
18
21
|
end
|
22
|
+
rescue CSV::MalformedCSVError => e
|
23
|
+
raise ParseError.new(e.message)
|
19
24
|
end
|
20
25
|
|
21
26
|
rdata
|
@@ -56,12 +61,16 @@ module Tolq::Parsers::CSV
|
|
56
61
|
|
57
62
|
def extract_request_data_from_csv(csv_text, parse_opts)
|
58
63
|
rdata = {}
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
+
begin
|
65
|
+
CSV.new(csv_text, parse_opts).each.with_index do |row, rowidx|
|
66
|
+
row.each.with_index do |col, colidx|
|
67
|
+
next if excluded?(colidx, rowidx)
|
68
|
+
charcol = ColumnHelper.column_to_char(colidx)
|
69
|
+
rdata["#{charcol}#{rowidx + 1}"] = { "text" => col } if col && col.length > 0
|
70
|
+
end
|
64
71
|
end
|
72
|
+
rescue CSV::MalformedCSVError => e
|
73
|
+
raise ParseError.new(e.message)
|
65
74
|
end
|
66
75
|
|
67
76
|
rdata
|
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.2.
|
4
|
+
version: 0.2.2
|
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-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|