Class: SheetsAPI::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/sheetsAPI.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(documentId: nil, documentName: 'unnamed') ⇒ Document

Returns a new instance of Document.



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/sheetsAPI.rb', line 83

def initialize(documentId: nil, documentName: 'unnamed')
  if !documentId
    file = DriveService.create_file(Google::Apis::DriveV3::File.new(mime_type: 'application/vnd.google-apps.spreadsheet', name: documentName))
    documentId = file.id
    a = Google::Apis::DriveV3::Permission.new(type: 'user', role: 'owner', email_address: '[email protected]')
    puts a.inspect
    DriveService.create_permission(documentId, a, transfer_ownership: true)
  end
  @id = documentId
  @document = SheetService.get_spreadsheet(documentId)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



94
95
96
# File 'lib/sheetsAPI.rb', line 94

def id
  @id
end

Instance Method Details

#sheet(sheetName) ⇒ Object



96
97
98
99
100
101
102
103
104
105
# File 'lib/sheetsAPI.rb', line 96

def sheet(sheetName)
  @sheetName = sheetName

  sheet = @document.sheets.find{|sheet| sheet.properties.title.downcase == sheetName.downcase}
  if !sheet
    createSheet(sheetName)
  end

  return Sheet.new(self, sheetName)
end