class Locraft::GoogleDriveWrapper
Constants
- EXPORTED_CSV_FILE
- SESSION_TOKEN_FILE
Public Class Methods
new(config)
click to toggle source
# File lib/locraft/google_drive_wrapper.rb, line 12 def initialize(config) @config = config end
Public Instance Methods
authenticate()
click to toggle source
# File lib/locraft/google_drive_wrapper.rb, line 16 def authenticate token_file = File.join(@config.from_folder, SESSION_TOKEN_FILE) @session = GoogleDrive.saved_session(token_file) end
doc_named(name)
click to toggle source
# File lib/locraft/google_drive_wrapper.rb, line 21 def doc_named(name) authenticate unless @session @session.spreadsheet_by_title(name) end
export_worksheet()
click to toggle source
return worksheet
# File lib/locraft/google_drive_wrapper.rb, line 27 def export_worksheet worksheets = doc_named(@config.gdoc_file)&.worksheets if worksheets.count > @config.gdoc_sheet worksheets[@config.gdoc_sheet] else warn 'gdrive_wrapper worksheet export error: You have no access to google_doc or sheet number in config out of bounds!' end end
export_worksheet_csv()
click to toggle source
return worksheet as string in csv format
# File lib/locraft/google_drive_wrapper.rb, line 46 def export_worksheet_csv worksheet = export_worksheet worksheet.export_as_string end
export_worksheet_file()
click to toggle source
return exported worksheet file path
# File lib/locraft/google_drive_wrapper.rb, line 38 def export_worksheet_file sheet = export_worksheet file = File.join(@config.relative_strings_destination, EXPORTED_CSV_FILE) File.delete(file) if File.exist?(file) sheet.export_as_file(file) end