Sha256: 8700d94f14d6837c975e4aae5ad9b25403ced7068855588f7116bb38d4dee16a

Contents?: true

Size: 913 Bytes

Versions: 3

Compression:

Stored size: 913 Bytes

Contents

class ActiveReport::Array < ActiveReport::Base

  attr_accessor :datum, :headers, :options

  def initialize(datum, headers: nil, options: {})
    @datum = datum
    @headers = headers
    @options = duplicate_options.merge!(options)
  end

  def self.export(datum, headers: nil, options: {})
    new(datum, headers: headers, options: options).export
  end

  def self.import(datum, headers: nil, options: {})
    new(datum, headers: headers, options: options).import
  end

  def export
    @datum = munge_first(@datum)

    CSV.generate(@options) do |csv|
      csv << @headers unless @headers.nil?
      @datum.lazy.each { |cell| csv << cell }
    end
  end

  def import
    datum = merge(@headers)

    CSV.foreach(@datum, @options) do |data|
      data = encode_to_utf8(data) if force_encoding?
      datum.push(data)
    end

    datum = datum.flatten if datum.size < 2
    metatransform(datum)
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_report-4.0.2 lib/active_report/array.rb
active_report-4.0.1 lib/active_report/array.rb
active_report-4.0.0 lib/active_report/array.rb