tolq-parsers-csv 0.2.0 → 0.2.1

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 +18 -0
  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: 1812d6b67495f8df13b3655c8578d65bf4fd78c6
4
- data.tar.gz: bf94b7f9246532fe12d4b85a51b2a652cb44418c
3
+ metadata.gz: 9710a9952e758a16ef163907a4dc149a99de1027
4
+ data.tar.gz: e52fb0b7058978b6558768cf2797a4eb76867ac6
5
5
  SHA512:
6
- metadata.gz: 289c3ba9652b4397abc6eee17e66dc2a795caf7ab076eeb44ebf4408afb58268536e37812382d38c1226dbd3724fcf7948b0ac98424cb875137938a16fde5727
7
- data.tar.gz: f1a0b5f9f7d06275f4c4c6672d2322e2265679f67e748a3938f5abe3d7cddab48db3734b5da8c27f7869085610ce6a436200d3cb508a0a5d8606d7bf8f75b036
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
@@ -1,7 +1,7 @@
1
1
  module Tolq
2
2
  module Parsers
3
3
  module CSV
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
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.2.0
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-03 00:00:00.000000000 Z
11
+ date: 2017-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler