Class: CSVPlusPlus::Options::FileOptions

Inherits:
Options
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/csv_plus_plus/options/file_options.rb

Overview

The options that are specific for compiling to a file

Instance Attribute Summary collapse

Attributes inherited from Options

#backup, #create_if_not_exists, #key_values, #offset, #overwrite_values, #sheet_name, #verbose

Instance Method Summary collapse

Constructor Details

#initialize(sheet_name, output_filename) ⇒ FileOptions

Initialize an Options object for writing to a file



18
19
20
21
22
# File 'lib/csv_plus_plus/options/file_options.rb', line 18

def initialize(sheet_name, output_filename)
  super(sheet_name)

  @output_filename = ::T.let(::Pathname.new(output_filename), ::Pathname)
end

Instance Attribute Details

#output_filenamePathname

The file to write our compiled results to

Returns:

  • (Pathname)

    the current value of output_filename



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

def output_filename
  @output_filename
end

Instance Method Details

#output_formatOptions::OutputFormat

Given the options, figure out which type of OutputFormat we’ll be writing to



28
29
30
31
32
33
34
35
# File 'lib/csv_plus_plus/options/file_options.rb', line 28

def output_format
  case output_filename.extname
  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::CLIError, "Unsupported file extension: #{output_filename}")
  end
end

#verbose_summaryString

Verbose summary for options specific to compiling to a file

Returns:

  • (String)


41
42
43
44
45
46
# File 'lib/csv_plus_plus/options/file_options.rb', line 41

def verbose_summary
  shared_summary(
    <<~OUTPUT)
      > Output filename                     | #{output_filename}
    OUTPUT
end