google_sheets 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -3
  3. data/lib/google_sheets/sheet.rb +16 -9
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b4000bd3f32057853f95287ca9056849a102150d00b391559db283d8d37f2e2
4
- data.tar.gz: 3810f53c188bef420dcf480d2cc05c66554fdf5f9e01fec5186127c1193a759d
3
+ metadata.gz: 8784a8e9d487e921e6e95a133cda24925ef38e946ba2e94dde9049c9db3020ac
4
+ data.tar.gz: 4b5f5d2a0c622610c942e5e59a36f4d53f571ec8e631bc531ca826e2ecfe9427
5
5
  SHA512:
6
- metadata.gz: 79c4d49b52421cbd15ad255049231f9496fb78d5754fb18df193822507bf98ebfd28bb873afeb2830f12adbc36f11f50ad5cb5868c82014ca67a0344724b6182
7
- data.tar.gz: b6f4346231bb72a86f111689a0d04c9e2e3c2811058fbdbe0011ca12fd609ea74cd045e93999635f7553cc076ff59ec99b9a0b4d375cf9225683a6fc76166e94
6
+ metadata.gz: db65c288119d44c821aca69ecf8d27a6c64400f7c4d25578661a22b3a8c2cd7dc3e402cfa4de5f3e46a49becd4b5d4b1be93438961a09aca022f08eb5bc9caf0
7
+ data.tar.gz: ec592fbaba4b61fc98302cd5a904cdce435b7085d0db451aa2c877f43a0049d682d8c17abceb348e514e8b77915e81b54d650eebc8b4322bbb0daccd9134665d
data/README.md CHANGED
@@ -57,7 +57,7 @@ session = GoogleSheets::Session.start_session(
57
57
 
58
58
  <h3 id='getting-started'>Getting Started</h3>
59
59
 
60
- Once you're authorized, you can read, create, and delete sheets within a spreadsheet.
60
+ Once you're authorized, you can create, read, update and delete sheets within a spreadsheet.
61
61
 
62
62
  ``` ruby
63
63
  session = GoogleSheets::Session.start_session(
@@ -105,10 +105,14 @@ sheet1_json = sheet1.to_json
105
105
 
106
106
  sheet1_json[0][:first] = 'bobby'
107
107
 
108
- sheet1.set_values_from_json sheet1_json
108
+ # Sheet#set_values_from_json is the inverse of to_json
109
+ # accepts an array of hashes, turns it back to csv format
110
+ # sets that as the sheet's values
111
+ sheet1.set_values_from_json(sheet1_json)
109
112
 
110
- expect(sheet1.values[1][0]).to eq('bobby')
113
+ sheet1.values[1][0] # => 'bobby'
111
114
 
115
+ # save the spreadsheet's values
112
116
  sheet1.save!
113
117
  ```
114
118
 
@@ -69,15 +69,7 @@ module GoogleSheets
69
69
  #
70
70
  # @return Array(Array)
71
71
  def set_values_from_json json
72
- top_row = json.map(&:keys).flatten.uniq
73
-
74
- csv = json.map do |hash|
75
- top_row.map {|c| hash[c] }
76
- end
77
-
78
- csv.unshift top_row.map &:to_s
79
-
80
- self.values = csv
72
+ self.values = Sheet.json_to_csv(json)
81
73
  end
82
74
 
83
75
  # Save the current `values` to the spreadsheet
@@ -90,6 +82,21 @@ module GoogleSheets
90
82
  @service.update_spreadsheet_value(@spreadsheet.key, @title, value_range_object, value_input_option: 'RAW')
91
83
  end
92
84
 
85
+ # Helper method for converting an array of hashes to csv-style values
86
+ # @param an array of hashes to be converted to csv-style nested array format
87
+ # @return [Array(Array)] csv style nested array
88
+ def self.json_to_csv json
89
+ top_row = json.map(&:keys).flatten.uniq
90
+
91
+ csv = json.map do |hash|
92
+ top_row.map {|c| hash[c] }
93
+ end
94
+
95
+ csv.unshift top_row.map &:to_s
96
+
97
+ csv
98
+ end
99
+
93
100
  private
94
101
 
95
102
  def hashify_data csv, top_row
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_sheets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Murphy