Module: LpCSVExportable::CanExportAsCSV

Defined in:
lib/lp_csv_exportable/can_export_as_csv.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



3
4
5
# File 'lib/lp_csv_exportable/can_export_as_csv.rb', line 3

def collection
  @collection
end

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/lp_csv_exportable/can_export_as_csv.rb', line 5

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#initialize(args = {}) ⇒ Object



9
10
11
12
# File 'lib/lp_csv_exportable/can_export_as_csv.rb', line 9

def initialize(args = {})
  @collection = args[:collection]
  after_init(args)
end

#to_csvObject



14
15
16
17
18
19
20
21
# File 'lib/lp_csv_exportable/can_export_as_csv.rb', line 14

def to_csv
  CSV.generate do |csv|
    csv << headers
    data_matrix.each do |row|
      csv << row
    end
  end
end