Class: CSVPlusPlus::Options

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

Overview

The options a user can supply

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

initialize



12
13
14
15
16
17
18
19
# File 'lib/csv_plus_plus/options.rb', line 12

def initialize
  @offset = [0, 0]
  @create_if_not_exists = false
  @key_values = {}
  @verbose = false
  # TODO: switch to true? probably a safer choice
  @backup = false
end

Instance Attribute Details

#backupObject

Returns the value of attribute backup.



8
9
10
# File 'lib/csv_plus_plus/options.rb', line 8

def backup
  @backup
end

#create_if_not_existsObject

Returns the value of attribute create_if_not_exists.



8
9
10
# File 'lib/csv_plus_plus/options.rb', line 8

def create_if_not_exists
  @create_if_not_exists
end

#googleObject (readonly)

Returns the value of attribute google.



9
10
11
# File 'lib/csv_plus_plus/options.rb', line 9

def google
  @google
end

#key_valuesObject

Returns the value of attribute key_values.



8
9
10
# File 'lib/csv_plus_plus/options.rb', line 8

def key_values
  @key_values
end

#offsetObject

Returns the value of attribute offset.



8
9
10
# File 'lib/csv_plus_plus/options.rb', line 8

def offset
  @offset
end

#output_filenameObject

Returns the value of attribute output_filename.



8
9
10
# File 'lib/csv_plus_plus/options.rb', line 8

def output_filename
  @output_filename
end

#sheet_nameObject

Returns the value of attribute sheet_name.



8
9
10
# File 'lib/csv_plus_plus/options.rb', line 8

def sheet_name
  @sheet_name
end

#verboseObject

Returns the value of attribute verbose.



8
9
10
# File 'lib/csv_plus_plus/options.rb', line 8

def verbose
  @verbose
end

Instance Method Details

#google_sheet_id=(sheet_id) ⇒ Object

Set the Google Sheet ID



22
23
24
# File 'lib/csv_plus_plus/options.rb', line 22

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

#to_sObject

to_s



59
60
61
62
# File 'lib/csv_plus_plus/options.rb', line 59

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

#validateObject

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



27
28
29
30
31
# File 'lib/csv_plus_plus/options.rb', line 27

def validate
  return if @google || @output_filename

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

#verbose_summaryObject

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/csv_plus_plus/options.rb', line 34

def verbose_summary
  "    \#{summary_divider}\n\n    # csv++ Command Options\n\n    > Input filename                      | \#{@filename}\n    > Sheet name                          | \#{@sheet_name}\n    > Create sheet if it does not exist?  | \#{@create_if_not_exists}\n    > Spreadsheet row-offset              | \#{@offset[0]}\n    > Spreadsheet cell-offset             | \#{@offset[1]}\n    > User-supplied key-values            | \#{@key_values}\n    > Verbose                             | \#{@verbose}\n\n    ## Output Options\n\n    > Backup                              | \#{@backup}\n    > Output filename                     | \#{@output_filename}\n\n    \#{@google&.verbose_summary || ''}\n    \#{summary_divider}\n  SUMMARY\nend\n"