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 +4 -4
- data/lib/csv/column_helper.rb +1 -1
- data/lib/csv/unparser.rb +18 -6
- data/lib/csv/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 205e1ec8ace94c2cf77ba5b546f7e45d3a897d5d
|
4
|
+
data.tar.gz: d822029f449818901d1ab1e4f452b5e974c8c704
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdf304eca2f197e86e4bd1d8ccf9b3de141591e2781f327af0449eb83ad208a32dcca31f219ce6f231899749a9efe0e9648a397a567ae1579ef14681531a94cc
|
7
|
+
data.tar.gz: d0ec5870fa88e724bf3443247669cd079655bfca356a916a9acdb550be9e328f45256e2054192d8001efb0645e82a4ab8d65158073b885f0abc2d5b2fb6b82c8
|
data/lib/csv/column_helper.rb
CHANGED
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
|
11
|
-
translations = tolq_response['translations']
|
12
|
-
|
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.
|
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