Skip to content

Instantly share code, notes, and snippets.

@octosteve
Created January 20, 2013 19:28
Show Gist options
  • Save octosteve/4581047 to your computer and use it in GitHub Desktop.
Save octosteve/4581047 to your computer and use it in GitHub Desktop.
Expenses With David
require 'google_drive'
class Transaction
def initialize(date, merchant, amount)
@date = date
@merchant = merchant
@amount = amount
end
def self.all
ws.rows.map{|row| Transaction.new row[0], row[1], row[2]}
end
def self.sheet=(sheet)
@@sheet = sheet
end
end
# set you session
session = GoogleDrive.login("[email protected]", "mypassword")
# Open file
ws = session.spreadsheet_by_key("pz7XtlQC-PYx-jrVMJErTcg").worksheets[0]
# to read do...
date = ws[1,1]
merchant = ws[2,1]
# ...
# Yet another way to do so.
p ws.rows #==> [["fuga", ""], ["foo", "bar]]
Transaction.sheet = ws
ws.rows.each{|row| Transaction.new row[0], row[1], row[2]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment