Class: Terrazzo::CsvExport

Inherits:
Object
  • Object
show all
Defined in:
lib/terrazzo/csv_export.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dashboard, resources) ⇒ CsvExport

Returns a new instance of CsvExport.



8
9
10
11
# File 'lib/terrazzo/csv_export.rb', line 8

def initialize(dashboard, resources)
  @dashboard = dashboard
  @resources = resources
end

Instance Attribute Details

#dashboardObject (readonly)

Returns the value of attribute dashboard.



6
7
8
# File 'lib/terrazzo/csv_export.rb', line 6

def dashboard
  @dashboard
end

#resourcesObject (readonly)

Returns the value of attribute resources.



6
7
8
# File 'lib/terrazzo/csv_export.rb', line 6

def resources
  @resources
end

Instance Method Details

#to_csvObject



13
14
15
16
17
18
19
20
21
# File 'lib/terrazzo/csv_export.rb', line 13

def to_csv
  CSV.generate(headers: true) do |csv|
    csv << attributes.map { |attr| header_for(attr) }

    resources.each do |resource|
      csv << attributes.map { |attr| value_for(resource, attr) }
    end
  end
end