Module: CSVPlusPlus::Options

Extended by:
T::Sig
Defined in:
lib/csv_plus_plus/options.rb,
lib/csv_plus_plus/options/options.rb,
lib/csv_plus_plus/options/file_options.rb,
lib/csv_plus_plus/options/google_sheets_options.rb

Overview

Options that a user can supply - either specific for compiling to a file (xlsx, csv) or Google Sheets

Defined Under Namespace

Classes: FileOptions, GoogleSheetsOptions, Options, OutputFormat

Class Method Summary collapse

Class Method Details

.from_cli_flags(flags, input_filename) ⇒ Options::Options

Use the given flags to determine if we’re dealing with either a Google Sheets or file-based compilation and build an Options instance accordingly.

Parameters:

  • flags (Hash<Symbol, String>)
  • input_filename (Pathname)

Returns:



29
30
31
32
33
34
35
36
37
38
# File 'lib/csv_plus_plus/options.rb', line 29

def self.from_cli_flags(flags, input_filename)
  sheet_name = flags[:'sheet-name'] || input_filename.sub_ext('').to_s
  if (google_sheet_id = flags[:'google-sheet-id'])
    ::CSVPlusPlus::Options::GoogleSheetsOptions.new(sheet_name, google_sheet_id)
  elsif (output_filename = flags[:output])
    ::CSVPlusPlus::Options::FileOptions.new(sheet_name, output_filename)
  else
    raise(::CSVPlusPlus::Error::CLIError, 'You must supply either -o/--output or -g/-google-sheet-id')
  end
end