Class: CSVPlusPlus::Writer::GoogleSheets

Inherits:
Writer
  • Object
show all
Extended by:
T::Sig
Includes:
GoogleApiClient
Defined in:
lib/csv_plus_plus/writer/google_sheets.rb

Overview

A class that can write a Template to Google Sheets (via their API)

Instance Attribute Summary

Attributes inherited from Writer

#position

Instance Method Summary collapse

Methods included from GoogleApiClient

#drive_client, #sheets_client

Constructor Details

#initialize(options, position) ⇒ GoogleSheets

Returns a new instance of GoogleSheets.

Parameters:



16
17
18
19
20
21
# File 'lib/csv_plus_plus/writer/google_sheets.rb', line 16

def initialize(options, position)
  super(position)

  @options = ::T.let(options, ::CSVPlusPlus::Options::GoogleSheetsOptions)
  @reader = ::T.let(::CSVPlusPlus::Reader::GoogleSheets.new(options), ::CSVPlusPlus::Reader::GoogleSheets)
end

Instance Method Details

#write(template) ⇒ Object

Write a template to Google Sheets

Parameters:



27
28
29
30
31
# File 'lib/csv_plus_plus/writer/google_sheets.rb', line 27

def write(template)
  create_sheet! if @options.create_if_not_exists

  update_cells!(template)
end

#write_backupObject

Write a backup of the Google Sheet that is about to be written



35
36
37
# File 'lib/csv_plus_plus/writer/google_sheets.rb', line 35

def write_backup
  drive_client.copy_file(@options.sheet_id)
end