google_spreadsheet_fetcher 1.0.0 → 1.1.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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf51e7e9a7e8375b321cff2bb3398cfe2234ca57af2c1952ea2fb1a272a9de27
|
4
|
+
data.tar.gz: 9e83feb58028dbe9344834f1067dc188fbd01b273bc25f8c1847a40119f8a2cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a7b5a6bc218f915bd4f987e7679157e0db5c89018b434f8ad76c9f4e647cfd0dc32c66e40053d07366165926b6638d37254fddf5043ffed8b7de5b55b035fa4
|
7
|
+
data.tar.gz: 0476d4f615072e193077a59855ad6236ee7ec1d52a0fc6eb0838284cbdb1e47e96236fde5e6aad4e4ffa41d2dee733be32e948ee3a443141fe0903110243d56f
|
@@ -20,19 +20,25 @@ module GoogleSpreadsheetFetcher
|
|
20
20
|
|
21
21
|
# @param [String] range(https://developers.google.com/sheets/api/guides/concepts#a1_notation)
|
22
22
|
# @param [Integer] skip
|
23
|
-
def fetch_all_rows(range, skip: 0)
|
23
|
+
def fetch_all_rows(range, skip: 0, structured: false)
|
24
24
|
rows = service.batch_get_spreadsheet_values(@spreadsheet_id, ranges: [range])&.value_ranges&.first&.values
|
25
25
|
return [] if rows.blank?
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
if structured
|
28
|
+
headers = rows.delete_at(0)
|
29
|
+
rows.slice!(0, skip)
|
30
|
+
rows.map { |r| [headers, r].transpose.to_h }
|
31
|
+
else
|
32
|
+
rows.slice!(0, skip)
|
33
|
+
rows
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
|
-
def fetch_all_rows_by!(index: nil, sheet_id: nil, title: nil, skip: 0)
|
37
|
+
def fetch_all_rows_by!(index: nil, sheet_id: nil, title: nil, skip: 0, structured: false)
|
32
38
|
sheet = fetch_sheet_by!(index: index, sheet_id: sheet_id, title: title)
|
33
39
|
|
34
40
|
range = "#{sheet.properties.title}!A:Z"
|
35
|
-
fetch_all_rows(range, skip: skip)
|
41
|
+
fetch_all_rows(range, skip: skip, structured: structured)
|
36
42
|
end
|
37
43
|
|
38
44
|
def service
|