class GrafanaReporter::CsvTableFormatStrategy

Implements a default table format strategy, which will return tables as CSV formatted strings.

Public Class Methods

abbreviation() click to toggle source

@see AbstractTableFormatStrategy#abbreviation

# File lib/grafana_reporter/csv_table_format_strategy.rb, line 8
def self.abbreviation
  'csv'
end

Public Instance Methods

format(result, include_headline) click to toggle source

@see AbstractTableFormatStrategy#format

# File lib/grafana_reporter/csv_table_format_strategy.rb, line 13
def format(result, include_headline)
  headline = result[:header].map { |item| item.to_s.gsub(',', '\\,') }.join(',')

  content = result[:content].map do |row|
    row.map { |item| item.to_s.gsub(',', '\,') }.join(',')
  end.join("\n")

  "#{"#{headline}\n" if include_headline}#{content}"
end