Class: Cloudsheet::Drive

Inherits:
Sheet
  • Object
show all
Defined in:
lib/cloudsheet/drive.rb

Instance Attribute Summary

Attributes inherited from Sheet

#raw_sheet, #workbook

Instance Method Summary collapse

Methods inherited from Sheet

#each, #map

Constructor Details

#initialize(hash) ⇒ Drive

Returns a new instance of Drive.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cloudsheet/drive.rb', line 5

def initialize(hash)
  if hash[:user] and hash[:password]
    drive = GoogleDrive.(hash[:user], hash[:password])
  elsif hash[:access_token]
    drive = GoogleDrive.(hash[:access_token])
  else
    raise "Missing Google Credentials"
  end

  if hash[:sheet_key]
    @workbook = drive.spreadsheet_by_key(hash[:sheet_key])
  else
    raise "Missing sheet key"
  end

  if hash[:sheet]
    @raw_sheet = @workbook.worksheets[hash[:sheet]]
  else
    @raw_sheet = @workbook.worksheets[0]
  end
end

Instance Method Details

#rowsObject



32
33
34
# File 'lib/cloudsheet/drive.rb', line 32

def rows
  super.drop(1)
end

#sheet(num) ⇒ Object



27
28
29
30
# File 'lib/cloudsheet/drive.rb', line 27

def sheet(num)
  @raw_sheet = @workbook.worksheets[num]
  self
end