Sha256: 657bcba53548ff333ba2f54ad8476915a4c9d51212680a683827db9d52b03a0c
Contents?: true
Size: 886 Bytes
Versions: 2
Compression:
Stored size: 886 Bytes
Contents
class ActiveReport::Array attr_accessor :datum, :headers, :options def initialize(datum, headers: nil, options: {}) @datum = datum @headers = headers @options = 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 = [].push(@datum).compact unless @datum.first.is_a?(Array) CSV.generate(@options) do |csv| csv << @headers unless @headers.nil? @datum.each { |data| csv << data } end end def import processed_datum = [].push(@headers).compact CSV.foreach(@datum, @options) do |data| processed_datum.push(data) end return(processed_datum.size < 2 ? processed_datum.flatten : processed_datum) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_report-2.2.0 | lib/active_report/array.rb |
active_report-2.0.0 | lib/active_report/array.rb |