Class: Defmastership::Export::CSV::Formatter

Inherits:
Formatter
  • Object
show all
Defined in:
lib/defmastership/export/csv/formatter.rb

Overview

to export a CSV file

Instance Attribute Summary

Attributes inherited from Formatter

#doc

Instance Method Summary collapse

Methods inherited from Formatter

#body, #header

Constructor Details

#initialize(doc, separator: ',') ⇒ Formatter

Returns a new instance of Formatter.

Parameters:

  • doc (Document)

    the document to export

  • separator (String) (defaults to: ',')

    the CSV separator



15
16
17
18
# File 'lib/defmastership/export/csv/formatter.rb', line 15

def initialize(doc, separator: ',')
  @sep = separator
  super(doc)
end

Instance Method Details

#export_to(output_file) ⇒ Object

Export the document to a CSV file

Parameters:

  • output_file (String)

    filename for the export



23
24
25
26
27
28
29
# File 'lib/defmastership/export/csv/formatter.rb', line 23

def export_to(output_file)
  column_list = build_column_list
  ::CSV.open(output_file, 'w:ISO-8859-1', col_sep: @sep) do |csv|
    csv << header(column_list)
    export_definitions_in(csv, column_list)
  end
end