Sha256: e88a29b0fe03d190a2675c148e2bd09d3178a38af94d32e994ce7515363663dc

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

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 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, context)}"
              result << "#{attributes[cell]}"
            else
              result << cell.to_s
            end
          end
          result
        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

3 entries across 3 versions & 1 rubygems

Version Path
csv_row_model-0.3.6 lib/csv_row_model/export/file_model.rb
csv_row_model-0.3.5 lib/csv_row_model/export/file_model.rb
csv_row_model-0.3.4 lib/csv_row_model/export/file_model.rb