Module: Enumerable

Defined in:
lib/to_google_spreadsheet.rb

Instance Method Summary collapse

Instance Method Details

#to_google_spreadsheet(worksheet, spreadsheet = nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/to_google_spreadsheet.rb', line 64

def to_google_spreadsheet(worksheet, spreadsheet = nil)
  # We do this explicityly instead of using the default_spreadsheet as default
  # in the parameters since we want to let people pass nil to indicate they
  # want to use the default spreadsheet.
  spreadsheet = GoogleSpreadsheet::Config.default_spreadsheet unless spreadsheet

  session = GoogleSpreadsheet.(GoogleSpreadsheet::Config.email, 
                                    GoogleSpreadsheet::Config.password)
  spreadsheet = session.spreadsheet_by_key(spreadsheet)
  ws = spreadsheet.find_or_create_worksheet_by_name(worksheet)
  ws.set_header_columns(self.first)
  ws.populate(self)
  ws.save
end