Class: Compendium::Presenters::CSV

Inherits:
Table show all
Defined in:
app/classes/compendium/presenters/csv.rb

Instance Attribute Summary

Attributes inherited from Table

#records, #settings, #totals

Instance Method Summary collapse

Methods inherited from Base

#to_s

Constructor Details

#initialize(object, &block) ⇒ CSV

Returns a new instance of CSV.



5
6
7
# File 'app/classes/compendium/presenters/csv.rb', line 5

def initialize(object, &block)
  super(nil, object, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Compendium::Presenters::Base

Instance Method Details

#renderObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/classes/compendium/presenters/csv.rb', line 9

def render
  ::CSV.generate do |csv|
    csv << headings.map{ |_, val| formatted_heading(val) }

    records.each do |row|
      csv << row.map{ |key, val| formatted_value(key, val) }
    end

    if has_totals_row?
      totals[totals.keys.first] = translate(:total)
      csv << totals.map do |key, val|
        formatted_value(key, val) unless settings.skipped_total_cols.include?(key.to_sym)
      end
    end
  end
end