Class: CSVPlusPlus::Writer::CSV
Overview
A class that can output a Template
to CSV
Instance Attribute Summary
Attributes inherited from Writer
Instance Method Summary collapse
-
#evaluate_cell(cell) ⇒ Object
Turn the cell into a CSV-.
-
#initialize(options, position) ⇒ CSV
constructor
A new instance of CSV.
-
#write(template) ⇒ Object
Write a
template
to CSV. -
#write_backup ⇒ Object
Write a backup of the current spreadsheet.
Methods included from Merger
Methods included from FileBackerUpper
Constructor Details
#initialize(options, position) ⇒ CSV
Returns a new instance of CSV.
17 18 19 20 21 22 |
# File 'lib/csv_plus_plus/writer/csv.rb', line 17 def initialize(, position) super(position) @reader = ::T.let(::CSVPlusPlus::Reader::CSV.new(), ::CSVPlusPlus::Reader::CSV) @options = end |
Instance Method Details
#evaluate_cell(cell) ⇒ Object
Turn the cell into a CSV-
45 46 47 48 49 50 51 |
# File 'lib/csv_plus_plus/writer/csv.rb', line 45 def evaluate_cell(cell) if (ast = cell.ast) "=#{ast.evaluate(@position)}" else cell.value end end |
#write(template) ⇒ Object
Write a template
to CSV
29 30 31 32 33 34 35 |
# File 'lib/csv_plus_plus/writer/csv.rb', line 29 def write(template) ::CSV.open(@options.output_filename, 'wb') do |csv| @position.map_rows(template.rows) do |row| csv << build_row(row) end end end |
#write_backup ⇒ Object
Write a backup of the current spreadsheet.
39 40 41 |
# File 'lib/csv_plus_plus/writer/csv.rb', line 39 def write_backup backup_file(@options) end |