Class: Marktable::Formatters::CSV

Inherits:
Object
  • Object
show all
Defined in:
lib/marktable/formatters/csv.rb

Class Method Summary collapse

Class Method Details

.format(rows, headers = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/marktable/formatters/csv.rb', line 8

def self.format(rows, headers = nil)
  return '' if rows.empty? && headers.nil?

  ::CSV.generate do |csv|
    csv << headers if headers
    rows.each do |row|
      csv << format_row(row)
    end
  end
end

.format_row(row) ⇒ Object



19
20
21
# File 'lib/marktable/formatters/csv.rb', line 19

def self.format_row(row)
  row.values.map { |val| val unless val.to_s.empty? }
end