Class: Munger::Render::CSV

Inherits:
Object
  • Object
show all
Defined in:
lib/munger/render/csv.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report) ⇒ CSV

Returns a new instance of CSV.



7
8
9
# File 'lib/munger/render/csv.rb', line 7

def initialize(report)
  @report = report
end

Instance Attribute Details

#reportObject (readonly)

Returns the value of attribute report.



5
6
7
# File 'lib/munger/render/csv.rb', line 5

def report
  @report
end

Instance Method Details

#renderObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/munger/render/csv.rb', line 11

def render
  output = []

  # header
  output << @report.columns.collect { |col| @report.column_title(col).to_s }.join(',')
  
  # body
  @report.process_data.each do |row|
    output << @report.columns.collect { |col| row[:data][col].to_s }.join(',')
  end
  
  output.join("\n")
end

#valid?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/munger/render/csv.rb', line 25

def valid?
  @report.is_a? Munger::Report
end