module CsvRowModel::Export::FileModel

Public Instance Methods

rows_template() click to toggle source

Safe to override

@return [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
# File lib/csv_row_model/export/file_model.rb, line 27
def rows_template
  @rows_template ||= self.class.row_names.map { |row_name| [row_name] }
end
setup(csv, context, with_headers: true) click to toggle source
# File lib/csv_row_model/export/file_model.rb, line 32
def setup(csv, context, with_headers: true); end
to_rows() click to toggle source

@return [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.
# File lib/csv_row_model/export/file_model.rb, line 8
def to_rows
  rows_template.map do |row|
    [].tap do |result|
      row.each do |cell|
        if header? cell
          result << self.class.format_header(cell, context)
        else
          result << cell.to_s
        end
      end
    end
  end
end

Private Instance Methods

header?(cell) click to toggle source
# File lib/csv_row_model/export/file_model.rb, line 37
def header?(cell)
  self.class.is_row_name? cell
end