Class: CSVPlusPlus::Options
- Inherits:
-
Object
- Object
- CSVPlusPlus::Options
- Defined in:
- lib/csv_plus_plus/options.rb
Overview
The options a user can supply (via CLI flags)
Instance Attribute Summary collapse
-
#backup ⇒ boolean
Create a backup of the spreadsheet before writing.
-
#create_if_not_exists ⇒ boolean
Create the spreadsheet if it does not exist?.
-
#google ⇒ GoogleOptions
readonly
Options that are specific to the Google Sheets writer.
-
#key_values ⇒ Hash
Additional variables that can be supplied to the template.
-
#offset ⇒ Array<Integer>
An [x, y] offset (array with two integers).
-
#output_filename ⇒ String
The file to write our compiled results to.
-
#sheet_name ⇒ String
The name of the spreadsheet to write to.
-
#verbose ⇒ boolean
Include extra verbose output?.
Instance Method Summary collapse
-
#google_sheet_id=(sheet_id) ⇒ String
Set the Google Sheet ID.
-
#initialize ⇒ Options
constructor
initialize.
- #to_s ⇒ String
-
#validate ⇒ String?
Returns an error string or nil if there are no validation problems.
-
#verbose_summary ⇒ String
Return a string with a verbose description of what we’re doing with the options.
Constructor Details
#initialize ⇒ Options
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
#backup ⇒ boolean
Create a backup of the spreadsheet before writing
17 18 19 |
# File 'lib/csv_plus_plus/options.rb', line 17 def backup @backup end |
#create_if_not_exists ⇒ boolean
Create the spreadsheet if it does not exist?
17 18 19 |
# File 'lib/csv_plus_plus/options.rb', line 17 def create_if_not_exists @create_if_not_exists end |
#google ⇒ GoogleOptions (readonly)
Options that are specific to the Google Sheets writer
17 18 19 |
# File 'lib/csv_plus_plus/options.rb', line 17 def google @google end |
#key_values ⇒ Hash
Additional variables that can be supplied to the template
17 18 19 |
# File 'lib/csv_plus_plus/options.rb', line 17 def key_values @key_values end |
#offset ⇒ Array<Integer>
An [x, y] offset (array with two integers)
17 18 19 |
# File 'lib/csv_plus_plus/options.rb', line 17 def offset @offset end |
#output_filename ⇒ String
The file to write our compiled results to
17 18 19 |
# File 'lib/csv_plus_plus/options.rb', line 17 def output_filename @output_filename end |
#sheet_name ⇒ String
The name of the spreadsheet to write to
17 18 19 |
# File 'lib/csv_plus_plus/options.rb', line 17 def sheet_name @sheet_name end |
#verbose ⇒ boolean
Include extra verbose output?
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
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_s ⇒ 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 |
#validate ⇒ String?
Returns an error string or nil if there are no validation problems
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_summary ⇒ String
Return a string with a verbose description of what we’re doing with the options
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 |