Class: CSVPlusPlus::Options
- Inherits:
-
Object
- Object
- CSVPlusPlus::Options
- Extended by:
- T::Sig
- Defined in:
- lib/csv_plus_plus/options.rb
Overview
The options a user can supply (via CLI flags)
Defined Under Namespace
Classes: OutputFormat
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 a default
Optionsobject. -
#output_format ⇒ Options::OutputFormat
Given the options, figure out which type of
OutputFormatwe’ll be writing to. -
#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 a default Options object
54 55 56 57 58 59 60 61 |
# File 'lib/csv_plus_plus/options.rb', line 54 def initialize @offset = ::T.let([0, 0], ::T::Array[::Integer]) @create_if_not_exists = ::T.let(false, ::T::Boolean) @key_values = ::T.let({}, ::T::Hash[::Symbol, ::String]) @verbose = ::T.let(false, ::T::Boolean) @backup = ::T.let(false, ::T::Boolean) @google = ::T.let(nil, ::T.nilable(::CSVPlusPlus::GoogleOptions)) end |
Instance Attribute Details
#backup ⇒ boolean
Create a backup of the spreadsheet before writing
15 16 17 |
# File 'lib/csv_plus_plus/options.rb', line 15 def backup @backup end |
#create_if_not_exists ⇒ boolean
Create the spreadsheet if it does not exist?
15 16 17 |
# File 'lib/csv_plus_plus/options.rb', line 15 def create_if_not_exists @create_if_not_exists end |
#google ⇒ GoogleOptions (readonly)
Options that are specific to the Google Sheets writer
15 16 17 |
# File 'lib/csv_plus_plus/options.rb', line 15 def google @google end |
#key_values ⇒ Hash
Additional variables that can be supplied to the template
15 16 17 |
# File 'lib/csv_plus_plus/options.rb', line 15 def key_values @key_values end |
#offset ⇒ Array<Integer>
An [x, y] offset (array with two integers)
15 16 17 |
# File 'lib/csv_plus_plus/options.rb', line 15 def offset @offset end |
#output_filename ⇒ String
The file to write our compiled results to
15 16 17 |
# File 'lib/csv_plus_plus/options.rb', line 15 def output_filename @output_filename end |
#sheet_name ⇒ String
The name of the spreadsheet to write to
15 16 17 |
# File 'lib/csv_plus_plus/options.rb', line 15 def sheet_name @sheet_name end |
#verbose ⇒ boolean
Include extra verbose output?
15 16 17 |
# File 'lib/csv_plus_plus/options.rb', line 15 def verbose @verbose end |
Instance Method Details
#google_sheet_id=(sheet_id) ⇒ ::String
Set the Google Sheet ID
70 71 72 |
# File 'lib/csv_plus_plus/options.rb', line 70 def google_sheet_id=(sheet_id) @google = ::CSVPlusPlus::GoogleOptions.new(sheet_id) end |
#output_format ⇒ Options::OutputFormat
Given the options, figure out which type of OutputFormat we’ll be writing to
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/csv_plus_plus/options.rb', line 78 def output_format return ::CSVPlusPlus::Options::OutputFormat::GoogleSheets if @google case @output_filename when /\.csv$/ then ::CSVPlusPlus::Options::OutputFormat::CSV when /\.ods$/ then ::CSVPlusPlus::Options::OutputFormat::OpenDocument when /\.xl(sx|sm|tx|tm)$/ then ::CSVPlusPlus::Options::OutputFormat::Excel else raise(::CSVPlusPlus::Error::Error, "Unsupported file extension: #{@output_filename}") end end |
#validate ⇒ String?
Returns an error string or nil if there are no validation problems
93 94 95 96 97 |
# File 'lib/csv_plus_plus/options.rb', line 93 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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/csv_plus_plus/options.rb', line 103 def verbose_summary " \#{summary_divider}\n\n # csv++ Command Options\n\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" |