Class: RVGP::Plot::GoogleDrive::ExportLocalCsvs

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ExportLocalCsvs

Output google-intentioned spreadsheet sheets, to csvs in a directory

Parameters:

  • options (Hash)

    The parameters governing this export

Options Hash (options):

  • :format (String)

    What format, to output the csvs in. Currently, The only supported value is ‘csv’.

  • :destination (String)

    The path to a folder, to export sheets into



21
22
23
24
25
26
27
# File 'lib/rvgp/plot/google-drive/output_csv.rb', line 21

def initialize(options)
  unless [(options[:format] == 'csv'), File.directory?(options[:destination])].all?
    raise StandardError, 'Invalid Options, missing :destination'
  end

  @destination = options[:destination]
end

Instance Attribute Details

#destinationString

The destination path, provided in the constructor

Returns:

  • (String)

    the current value of destination



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

Parameters:



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