Sha256: 27bcacd3d769a6e7c8342e5e56fc760040b602708d57e511517f7d0ea22c9d68

Contents?: true

Size: 843 Bytes

Versions: 2

Compression:

Stored size: 843 Bytes

Contents

module ActiveList
  module Exporters
    class CsvExporter < AbstractExporter

      def file_extension
        'csv'
      end

      def mime_type
        Mime[:csv]
      end

      def generate_data_code
        record = 'r'
        code = generator.select_data_code(paginate: false)
        code << "data = ::CSV.generate do |csv|\n"
        code << "  csv << [#{columns_to_array(:header).join(', ')}]\n"
        code << "  for #{record} in #{generator.records_variable_name}\n"
        code << "    csv << [#{columns_to_array(:body, record: record).join(', ')}]\n"
        code << "  end\n"
        code << "end\n"
        code.c
      end

      def send_data_code
        "send_data(data, type: #{mime_type.to_s.inspect}, disposition: 'inline', filename: file_name.parameterize + '.#{file_extension}')\n".c
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_list-8.1.0 lib/active_list/exporters/csv_exporter.rb
active_list-7.3.0 lib/active_list/exporters/csv_exporter.rb