Class: RVGP::Plot::GoogleDrive::ExportLocalCsvs
- Inherits:
-
Object
- Object
- RVGP::Plot::GoogleDrive::ExportLocalCsvs
- Defined in:
- lib/rvgp/plot/google-drive/output_csv.rb
Overview
This class is roughly, an kind of diagnostic alternative to ExportSheets, which implements the :csvdir option of the Commands::PublishGsheets command. Mostly, this object offers the methods that ExportSheets provides, and writes the sheets that would have otherwise been published to google - into a local directory, with csv files representing the Google sheet. This is mostly a debugging and diagnostic function.
Instance Attribute Summary collapse
-
#destination ⇒ String
The destination path, provided in the constructor.
Instance Method Summary collapse
-
#initialize(options) ⇒ ExportLocalCsvs
constructor
Output google-intentioned spreadsheet sheets, to csvs in a directory.
-
#sheet(sheet) ⇒ void
Ouput the provided sheet, into the destination path, as a csv.
Constructor Details
#initialize(options) ⇒ ExportLocalCsvs
Output google-intentioned spreadsheet sheets, to csvs in a directory
21 22 23 24 25 26 27 |
# File 'lib/rvgp/plot/google-drive/output_csv.rb', line 21 def initialize() unless [([:format] == 'csv'), File.directory?([:destination])].all? raise StandardError, 'Invalid Options, missing :destination' end @destination = [:destination] end |
Instance Attribute Details
#destination ⇒ String
The destination path, provided in the constructor
13 14 15 |
# File 'lib/rvgp/plot/google-drive/output_csv.rb', line 13 def destination @destination end |
Instance Method Details
#sheet(sheet) ⇒ void
This method returns an undefined value.
Ouput the provided sheet, into the destination path, as a csv
32 33 34 35 36 37 38 39 40 |
# File 'lib/rvgp/plot/google-drive/output_csv.rb', line 32 def sheet(sheet) shortname = sheet.title.tr('^a-zA-Z0-9', '_').gsub(/_+/, '_').downcase.chomp('_') CSV.open([destination.chomp('/'), '/', shortname, '.csv'].join, 'wb') do |csv| ([sheet.columns] + sheet.rows).each do |row| csv << row.map { |c| c.is_a?(Date) ? c.strftime('%m/%d/%Y') : c } end end end |