Sha256: 8f37bc374cdef40c666a692d9275d9bd6bc1fab855623ac877aeb306fcf6cbf4

Contents?: true

Size: 1002 Bytes

Versions: 1

Compression:

Stored size: 1002 Bytes

Contents

module CsvRowModel
  module Export
    module FileModel
      extend ActiveSupport::Concern

      # @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.
      def to_rows
        rows_template.map.with_index do |row, index|
          row.map do |cell|
            self.class.row_names.include?(cell) ? self.class.format_header(cell, index, context) : cell.to_s
          end
        end
      end

      # 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
      def rows_template
        @rows_template ||= self.class.row_names.map { |row_name| [row_name] }
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csv_row_model-1.0.0.beta2 lib/csv_row_model/export/file_model.rb