Created
November 14, 2012 23:46
-
-
Save marvinahv/4075668 to your computer and use it in GitHub Desktop.
Belongs_to Functionality for Google Drive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'google_drive' | |
def recursive(i=0) | |
$arr[i].each do |row| | |
subs = [] | |
recursive(i+1) if $arr[i+1] | |
if (i+1) < ($arr.length) | |
$arr[i+1].each do |sub_row| | |
if sub_row["belongs_to"] == row["id"] | |
subs << sub_row | |
end | |
end | |
unless subs.empty? | |
subs_hash = { "children" => subs } | |
row.merge!(subs_hash) | |
end | |
end | |
end | |
end | |
def get_data(key) | |
google_session = GoogleDrive.login('username@gmail.com', 'password') | |
worksheets = google_session.spreadsheet_by_key(key).worksheets() | |
$arr = [] | |
worksheets.each do |worksheet| | |
arr = worksheet.list.to_hash_array | |
$arr << arr | |
end | |
recursive() | |
return $arr[0] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment