Class: Babelish::GoogleDoc
- Inherits:
-
Object
- Object
- Babelish::GoogleDoc
- Defined in:
- lib/babelish/google_doc.rb
Instance Attribute Summary collapse
-
#session ⇒ Object
Returns the value of attribute session.
Instance Method Summary collapse
- #authenticate ⇒ Object
- #download(requested_filename) ⇒ Object
- #download_spreadsheet(requested_filename, output_filename, worksheet_index = 0) ⇒ Object
- #file_with_name(name) ⇒ Object
- #open(requested_filename) ⇒ Object
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
13 14 15 |
# File 'lib/babelish/google_doc.rb', line 13 def session @session end |
Instance Method Details
#authenticate ⇒ Object
42 43 44 45 |
# File 'lib/babelish/google_doc.rb', line 42 def authenticate # will try to get token and store in file below @session = GoogleDrive.saved_session ".babelish.token" end |
#download(requested_filename) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# 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) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/babelish/google_doc.rb', line 25 def download_spreadsheet(requested_filename, output_filename, worksheet_index = 0) output_filename ||= "translations.csv" file = file_with_name(requested_filename) return nil unless file file.export_as_file(output_filename, "csv", worksheet_index) return output_filename end |
#file_with_name(name) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/babelish/google_doc.rb', line 47 def file_with_name(name) unless @session authenticate end result = @session.file_by_title(name) if result.is_a? Array file = result.first else file = result end end |
#open(requested_filename) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/babelish/google_doc.rb', line 33 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 |