Skip to content

Instantly share code, notes, and snippets.

@marvinahv
Created November 14, 2012 23:46
Show Gist options
  • Save marvinahv/4075668 to your computer and use it in GitHub Desktop.
Save marvinahv/4075668 to your computer and use it in GitHub Desktop.
Belongs_to Functionality for Google Drive
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