tolq-parsers-csv 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7be72ed5bca2afea101a8730b76b7d343a8e72b9
4
- data.tar.gz: eeec7078310453d3ce357768b6231e86545fa645
3
+ metadata.gz: 205e1ec8ace94c2cf77ba5b546f7e45d3a897d5d
4
+ data.tar.gz: d822029f449818901d1ab1e4f452b5e974c8c704
5
5
  SHA512:
6
- metadata.gz: 76b8c166f3ccda4b9a43538ccb4a0602e997d1a4f896a08a5b7b58a5d489e3a213d536510a444d24e15ad3952ecce4e9e253b9aa1ff7be401e9a516605d27297
7
- data.tar.gz: b74da6601b71c2816da38ab93286ad6cd01c7f9d0e68663d32b97be1e4ff7e1e40f00e3b67ebc49cda95330f1d8418258d118fc1ceae4d91325a536e215beadc
6
+ metadata.gz: cdf304eca2f197e86e4bd1d8ccf9b3de141591e2781f327af0449eb83ad208a32dcca31f219ce6f231899749a9efe0e9648a397a567ae1579ef14681531a94cc
7
+ data.tar.gz: d0ec5870fa88e724bf3443247669cd079655bfca356a916a9acdb550be9e328f45256e2054192d8001efb0645e82a4ab8d65158073b885f0abc2d5b2fb6b82c8
@@ -24,7 +24,7 @@ module Tolq::Parsers::CSV
24
24
  end
25
25
 
26
26
  def self.from_char_notation(key)
27
- char, row = key.scan(/([aA-zZ]+)(\d+)/).first
27
+ char, row = key.scan(/([A-Z]+)(\d+)/).first
28
28
  return row.to_i - 1, ColumnHelper.char_to_column(char)
29
29
  end
30
30
  end
data/lib/csv/unparser.rb CHANGED
@@ -7,20 +7,32 @@ module Tolq::Parsers::CSV
7
7
  #
8
8
  # @param tolq_response [Hash] A parsed response from our api
9
9
  # @return [String] A csv formatted string
10
- def unparse(tolq_response)
11
- translations = tolq_response['translations']
12
- CSV.generate do |csv|
10
+ def from_tolq_response(tolq_response)
11
+ translations = tolq_response['translations'].values.first
12
+ generate_csv(translations)
13
+ end
14
+
15
+ # Unparses a translations hash of key => translation
16
+ #
17
+ # @param translations [Hash] A hash of translations with key => translation
18
+ # @return [String] A csv formatted string
19
+ def from_hash(translations)
20
+ generate_csv(translations)
21
+ end
22
+
23
+ private
24
+
25
+ def generate_csv(translations)
26
+ CSV.generate(force_quotes: true) do |csv|
13
27
  build_translation_matrix(translations).each do |row|
14
28
  csv << row.fill(nil, row.length..@maxcol)
15
29
  end
16
30
  end
17
31
  end
18
32
 
19
- private
20
-
21
33
  def build_translation_matrix(translations_hash)
22
34
  @maxcol = 0
23
- translations_hash.values.first.inject([]) do |matrix, (k,translation)|
35
+ translations_hash.inject([]) do |matrix, (k,translation)|
24
36
  row,col = ColumnHelper.from_char_notation(k)
25
37
  matrix[row] ||= []
26
38
  matrix[row][col] = translation
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.3"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tolq-parsers-csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timon Vonk