class Babelish::GoogleDoc
Attributes
session[RW]
Public Instance Methods
authenticate()
click to toggle source
# File lib/babelish/google_doc.rb, line 43 def authenticate # will try to get token and store in file below @session = GoogleDrive.saved_session ".babelish.token" end
download(requested_filename)
click to toggle source
# File lib/babelish/google_doc.rb, line 15 def download(requested_filename) file = file_with_name(requested_filename) return [] unless file files = [] file.worksheets.each_with_index do |worksheet, index| files << download_spreadsheet(requested_filename, "translations_#{worksheet.title}.csv", index) end files end
download_spreadsheet(requested_filename, output_filename, worksheet_index = 0)
click to toggle source
# File lib/babelish/google_doc.rb, line 25 def download_spreadsheet(requested_filename, output_filename, worksheet_index = 0) output_filename ||= "translations.csv" spreadsheet = file_with_name(requested_filename) return nil unless spreadsheet worksheet = spreadsheet.worksheets[worksheet_index] worksheet.export_as_file(output_filename) return output_filename end
file_with_name(name)
click to toggle source
# File lib/babelish/google_doc.rb, line 48 def file_with_name(name) unless @session authenticate end @session.spreadsheet_by_title(name) end
open(requested_filename)
click to toggle source
# File lib/babelish/google_doc.rb, line 34 def open(requested_filename) file = file_with_name(requested_filename) if file system "open \"#{file.human_url}\"" else puts "can't open requested file" end end