tolq-parsers-csv 0.2.0 → 0.2.1
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 -0
- 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: 9710a9952e758a16ef163907a4dc149a99de1027
|
4
|
+
data.tar.gz: e52fb0b7058978b6558768cf2797a4eb76867ac6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8dbb132f786549eeafee7fcbf3577de810631252849d401e5621492bd664689c638f8a333dda0800954702eab613adaa5c1357b55c7289c0bfe93ede7a239c4
|
7
|
+
data.tar.gz: 2e67d3d8065f4a913299932006ddcce301fd050f05ef1265495a25a1f37553c76ce1db9ceb5dd82ec1eb7f7ebe44379108446ca974ad7e95bc84b8cfcb1a9945
|
data/lib/csv/parser.rb
CHANGED
@@ -3,6 +3,24 @@ require 'csv'
|
|
3
3
|
module Tolq::Parsers::CSV
|
4
4
|
class Parser
|
5
5
|
|
6
|
+
# Helper method to convert a CSV into a annotated hash. Note that format
|
7
|
+
# is different from the Tolq api. It's just a hash.
|
8
|
+
#
|
9
|
+
# @param csv_io [IO] String or IO of csv
|
10
|
+
# @param parse_opts [Hash] Options for the CSV parser
|
11
|
+
# @return [Hash] Hash representation of csv, i.e. { 'A1' => 'Hello World'
|
12
|
+
def self.to_hash(csv_io, **parse_opts)
|
13
|
+
rdata = {}
|
14
|
+
CSV.new(csv_io, parse_opts).each.with_index do |row, rowidx|
|
15
|
+
row.each.with_index do |col, colidx|
|
16
|
+
charcol = ColumnHelper.column_to_char(colidx)
|
17
|
+
rdata["#{charcol}#{rowidx + 1}"] = col if col && col.length > 0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
rdata
|
22
|
+
end
|
23
|
+
|
6
24
|
# Creates a new csv parser
|
7
25
|
#
|
8
26
|
# @param quality [Symbol] the Tolq quality to order in
|
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.1
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|