Class: Defmastership::Export::Formatter
- Inherits:
-
Object
- Object
- Defmastership::Export::Formatter
- Defined in:
- lib/defmastership/export/formatter.rb
Overview
to export a CSV file
Direct Known Subclasses
CSV::Formatter, JSON::Formatter, XLSX::Formatter, YAML::Formatter
Defined Under Namespace
Modules: Helper
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Instance Method Summary collapse
-
#body(definition, column_list) ⇒ Array<String>
Build content of a row from the list of columns.
-
#export_to(_output_file) ⇒ Object
Export the document to a CSV file.
-
#header(column_list) ⇒ Array<String>
Build content of the header from the list of columns.
-
#initialize(doc) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(doc) ⇒ Formatter
Returns a new instance of Formatter.
15 16 17 |
# File 'lib/defmastership/export/formatter.rb', line 15 def initialize(doc) @doc = doc end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
12 13 14 |
# File 'lib/defmastership/export/formatter.rb', line 12 def doc @doc end |
Instance Method Details
#body(definition, column_list) ⇒ Array<String>
Build content of a row from the list of columns
41 42 43 44 45 |
# File 'lib/defmastership/export/formatter.rb', line 41 def body(definition, column_list) body_formatter = BodyFormatter.new(doc, definition) body_line = column_list.map { |part| body_formatter.public_send(part) } body_line.flatten end |
#export_to(_output_file) ⇒ Object
Export the document to a CSV file
22 23 24 |
# File 'lib/defmastership/export/formatter.rb', line 22 def export_to(_output_file) raise(NotImplementedError, "#{self.class} has not implemented the 'export_to' method") end |
#header(column_list) ⇒ Array<String>
Build content of the header from the list of columns
30 31 32 33 34 |
# File 'lib/defmastership/export/formatter.rb', line 30 def header(column_list) header_formatter = HeaderFormatter.new(doc) header_line = column_list.map { |part| header_formatter.public_send(part) } header_line.flatten end |