Module: CsvRowModel::Export::FileModel

Extended by:
ActiveSupport::Concern
Defined in:
lib/csv_row_model/export/file_model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.setup(csv, context, with_headers: true) ⇒ Object



34
# File 'lib/csv_row_model/export/file_model.rb', line 34

def setup(csv, context, with_headers: true); end

Instance Method Details

#rows_templateArray<Array>

Safe to override

Returns:

  • (Array<Array>)

    an array of arrays, where every represents a row and every row can have strings and row_name (column_name). By default, returns a row_name for every row



29
30
31
# File 'lib/csv_row_model/export/file_model.rb', line 29

def rows_template
  @rows_template ||= self.class.row_names.map { |row_name| [row_name] }
end

#to_rowsArray

Returns an array of rows, where if cell is row_name, it's parsed into the header_match and everything else is return as is.

Returns:

  • (Array)

    an array of rows, where if cell is row_name, it's parsed into the header_match and everything else is return as is.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/csv_row_model/export/file_model.rb', line 8

def to_rows
  rows_template.map do |row|
    result = []
    row.each do |cell|
      if self.class.is_row_name? cell
        header_matchs = self.class.options(cell)[:header_matchs]
        result << "#{header_matchs ? header_matchs.first : self.class.format_header(cell)}"
        result << "#{attributes[cell]}"
      else
        result << cell.to_s
      end
    end
    result
  end
end