Class: Tableizer::CsvTable

Inherits:
Object
  • Object
show all
Defined in:
lib/tableizer/csv_table.rb

Instance Method Summary collapse

Instance Method Details

#convert(data) ⇒ Object



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

def convert(data)
  case data
  when Time
    data.strftime("%Y-%m-%d %H:%M:%S")
  else
    data
  end
end

#to_s(cols_info, rows) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/tableizer/csv_table.rb', line 5

def to_s(cols_info, rows)
  CSV.generate do |csv|
    csv << cols_info.map{|col_info| col_info.header}
    rows.each do |row|
      csv << row.map { |col| convert(col) }
    end
  end
end