Sha256: 10794a86894c5802da431b21120f4d779cdf9e189d6a6c2c2881ca1f27a91001

Contents?: true

Size: 1.39 KB

Versions: 17

Compression:

Stored size: 1.39 KB

Contents

module ActiveList
  module Exporters
    class AbstractExporter
      attr_reader :table, :generator

      def initialize(generator)
        @generator = generator
        @table = generator.table
      end

      def file_extension
        'txt'
      end

      def mime_type
        Mime::TEXT
      end

      def send_data_code
        raise NotImplementedError, "#{self.class.name}#format_data_code is not implemented."
      end

      def columns_headers(options = {})
        headers = []
        columns = table.exportable_columns
        for column in columns
          datum = column.header_code
          headers << (options[:encoding] ? datum + ".to_s.encode('#{options[:encoding]}', invalid: :replace, undef: :replace)" : datum)
        end
        headers
      end

      def columns_to_array(nature, options = {})
        columns = table.exportable_columns

        array = []
        record = options[:record] || 'record_of_the_death'
        for column in columns
          next unless column.is_a?(ActiveList::Definition::AbstractColumn)
          datum = if nature == :header
                    column.header_code
                  else
                    column.exporting_datum_code(record)
                  end
          array << (options[:encoding] ? datum + ".to_s.encode('#{options[:encoding]}', invalid: :replace, undef: :replace)" : datum)
        end
        array
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
active_list-8.0.0 lib/active_list/exporters/abstract_exporter.rb
active_list-7.2.0 lib/active_list/exporters/abstract_exporter.rb
active_list-7.1.0 lib/active_list/exporters/abstract_exporter.rb
active_list-7.0.0 lib/active_list/exporters/abstract_exporter.rb
active_list-6.10.0 lib/active_list/exporters/abstract_exporter.rb
active_list-6.9.4 lib/active_list/exporters/abstract_exporter.rb
active_list-6.9.3 lib/active_list/exporters/abstract_exporter.rb
active_list-6.9.2 lib/active_list/exporters/abstract_exporter.rb
active_list-6.9.1 lib/active_list/exporters/abstract_exporter.rb
active_list-6.9.0 lib/active_list/exporters/abstract_exporter.rb
active_list-6.8.3 lib/active_list/exporters/abstract_exporter.rb
active_list-6.8.2 lib/active_list/exporters/abstract_exporter.rb
active_list-6.8.1 lib/active_list/exporters/abstract_exporter.rb
active_list-6.8.0 lib/active_list/exporters/abstract_exporter.rb
active_list-6.7.6 lib/active_list/exporters/abstract_exporter.rb
active_list-6.7.5 lib/active_list/exporters/abstract_exporter.rb
active_list-6.7.4 lib/active_list/exporters/abstract_exporter.rb