Class: ActiveReport::Array
Instance Attribute Summary collapse
-
#datum ⇒ Object
Returns the value of attribute datum.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
- .export(datum, headers: nil, options: {}) ⇒ Object
- .import(datum, headers: nil, options: {}) ⇒ Object
Instance Method Summary collapse
- #export ⇒ Object
- #import ⇒ Object
-
#initialize(datum, headers: nil, options: {}) ⇒ Array
constructor
A new instance of Array.
Methods inherited from Base
Constructor Details
#initialize(datum, headers: nil, options: {}) ⇒ Array
Returns a new instance of Array.
5 6 7 8 |
# File 'lib/active_report/array.rb', line 5 def initialize(datum, headers: nil, options: {}) @datum, @headers = datum, headers @options = .merge!() end |
Instance Attribute Details
#datum ⇒ Object
Returns the value of attribute datum.
3 4 5 |
# File 'lib/active_report/array.rb', line 3 def datum @datum end |
#headers ⇒ Object
Returns the value of attribute headers.
3 4 5 |
# File 'lib/active_report/array.rb', line 3 def headers @headers end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/active_report/array.rb', line 3 def @options end |
Class Method Details
.export(datum, headers: nil, options: {}) ⇒ Object
10 11 12 |
# File 'lib/active_report/array.rb', line 10 def self.export(datum, headers: nil, options: {}) new(datum, headers: headers, options: ).export end |
.import(datum, headers: nil, options: {}) ⇒ Object
14 15 16 |
# File 'lib/active_report/array.rb', line 14 def self.import(datum, headers: nil, options: {}) new(datum, headers: headers, options: ).import end |
Instance Method Details
#export ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/active_report/array.rb', line 18 def export @datum = munge_first(@datum) CSV.generate(@options) do |csv| csv << @headers unless @headers.nil? @datum.lazy.each { |cell| csv << cell } end end |
#import ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/active_report/array.rb', line 27 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 datum = (datum) datum end |