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: 5a797f4e71d74b4c24d5005bf91c06e699baab814970e1c4d6070808550bfa41
4
- data.tar.gz: 3822500ace1a0d202f0b6739b1e99f68163b4b5c1577b4ac434c470ef59a684a
3
+ metadata.gz: cf51e7e9a7e8375b321cff2bb3398cfe2234ca57af2c1952ea2fb1a272a9de27
4
+ data.tar.gz: 9e83feb58028dbe9344834f1067dc188fbd01b273bc25f8c1847a40119f8a2cf
5
5
  SHA512:
6
- metadata.gz: 4592c56919027ea291b6a773e0c83417051db6469a5aae1acf3324b016f90db6a83bb0c5a825afa7615a12e0e2c74abb55a46535e1fd84e37015bba50406920f
7
- data.tar.gz: '09340c7e08bfcac42337476365ab53277b93b71946ef8797c52c9c7013dd77eb30b4ddd2a11e3ac13c61c441f2854f8aa8c4aaa27c6eb05b3f2f241c65ba138b'
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
- rows.slice!(0, skip)
28
- rows
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
@@ -1,3 +1,3 @@
1
1
  module GoogleSpreadsheetFetcher
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_spreadsheet_fetcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiro Ooishi