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

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

Overview

to export a CSV file

Instance Method Summary collapse

Constructor Details

#initialize(doc, sep) ⇒ Formatter

Returns a new instance of Formatter.

Parameters:

  • doc (Document)

    the document to export

  • sep (String)

    the CSV separator



17
18
19
20
# File 'lib/defmastership/export/csv/formatter.rb', line 17

def initialize(doc, sep)
  @doc = doc
  @sep = sep
end

Instance Method Details

#export_to(output_file) ⇒ Object

Export the document to a CSV file

Parameters:

  • output_file (Strinf)

    filename for the export



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

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