Class: Google::Visualization::Formatter::CSV

Inherits:
Object
  • Object
show all
Defined in:
lib/google_visualization/formatter/csv.rb

Overview

JSON Formatter

Description

Serializes a DataTable to Comma Separated values (CSV)

Class Method Summary collapse

Class Method Details

.render(data_table) ⇒ Object

Generates a JSON string representation of a data table.



18
19
20
21
22
23
24
25
26
27
# File 'lib/google_visualization/formatter/csv.rb', line 18

def self.render(data_table)
  output = ""
  ::CSV::Writer.generate(output) do |csv|
    csv << data_table.columns.map(&:label)
    data_table.rows.each do |row|
      csv << row.cells.map(&:value)
    end
  end
  output
end