Class: CSVPlusPlus::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_plus_plus/options.rb

Overview

The options a user can supply (via CLI flags)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

initialize



22
23
24
25
26
27
28
# File 'lib/csv_plus_plus/options.rb', line 22

def initialize
  @offset = [0, 0]
  @create_if_not_exists = false
  @key_values = {}
  @verbose = false
  @backup = false
end

Instance Attribute Details

#backupboolean

Create a backup of the spreadsheet before writing

Returns:

  • (boolean)

    the current value of backup



17
18
19
# File 'lib/csv_plus_plus/options.rb', line 17

def backup
  @backup
end

#create_if_not_existsboolean

Create the spreadsheet if it does not exist?

Returns:

  • (boolean)

    the current value of create_if_not_exists



17
18
19
# File 'lib/csv_plus_plus/options.rb', line 17

def create_if_not_exists
  @create_if_not_exists
end

#googleGoogleOptions (readonly)

Options that are specific to the Google Sheets writer

Returns:



17
18
19
# File 'lib/csv_plus_plus/options.rb', line 17

def google
  @google
end

#key_valuesHash

Additional variables that can be supplied to the template

Returns:

  • (Hash)

    the current value of key_values



17
18
19
# File 'lib/csv_plus_plus/options.rb', line 17

def key_values
  @key_values
end

#offsetArray<Integer>

An [x, y] offset (array with two integers)

Returns:

  • (Array<Integer>)

    the current value of offset



17
18
19
# File 'lib/csv_plus_plus/options.rb', line 17

def offset
  @offset
end

#output_filenameString

The file to write our compiled results to

Returns:

  • (String)

    the current value of output_filename



17
18
19
# File 'lib/csv_plus_plus/options.rb', line 17

def output_filename
  @output_filename
end

#sheet_nameString

The name of the spreadsheet to write to

Returns:

  • (String)

    the current value of sheet_name



17
18
19
# File 'lib/csv_plus_plus/options.rb', line 17

def sheet_name
  @sheet_name
end

#verboseboolean

Include extra verbose output?

Returns:

  • (boolean)

    the current value of verbose



17
18
19
# File 'lib/csv_plus_plus/options.rb', line 17

def verbose
  @verbose
end

Instance Method Details

#google_sheet_id=(sheet_id) ⇒ String

Set the Google Sheet ID

Parameters:

  • sheet_id (String)

    The identifier used by Google’s API to reference the sheet. You can find it in the URL for the sheet

Returns:

  • (String)


36
37
38
# File 'lib/csv_plus_plus/options.rb', line 36

def google_sheet_id=(sheet_id)
  @google = ::CSVPlusPlus::GoogleOptions.new(sheet_id)
end

#to_sString

Returns:

  • (String)


77
78
79
80
# File 'lib/csv_plus_plus/options.rb', line 77

def to_s
  "Options(create_if_not_exists: #{@create_if_not_exists}, google: #{@google}, key_values: #{@key_values}, " \
    "offset: #{@offset}, sheet_name: #{@sheet_name}, verbose: #{@verbose})"
end

#validateString?

Returns an error string or nil if there are no validation problems

Returns:

  • (String, nil)


43
44
45
46
47
# File 'lib/csv_plus_plus/options.rb', line 43

def validate
  return if @google || @output_filename

  'You must supply either a Google Sheet ID or an output file'
end

#verbose_summaryString

Return a string with a verbose description of what we’re doing with the options

Returns:

  • (String)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/csv_plus_plus/options.rb', line 52

def verbose_summary
  <<~SUMMARY
    #{summary_divider}

    # csv++ Command Options

    > Input filename                      | #{@filename}
    > Sheet name                          | #{@sheet_name}
    > Create sheet if it does not exist?  | #{@create_if_not_exists}
    > Spreadsheet row-offset              | #{@offset[0]}
    > Spreadsheet cell-offset             | #{@offset[1]}
    > User-supplied key-values            | #{@key_values}
    > Verbose                             | #{@verbose}

    ## Output Options

    > Backup                              | #{@backup}
    > Output filename                     | #{@output_filename}

    #{@google&.verbose_summary || ''}
    #{summary_divider}
  SUMMARY
end