Class: Mpql::Formatters::TableFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/mpql/formatters/table_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ TableFormatter

Returns a new instance of TableFormatter.



10
11
12
# File 'lib/mpql/formatters/table_formatter.rb', line 10

def initialize(data)
  @builder = RowBuilder.new(data)
end

Instance Method Details

#renderObject



14
15
16
17
18
19
20
# File 'lib/mpql/formatters/table_formatter.rb', line 14

def render
  table = Terminal::Table.new(
    headings: @builder.headers,
    rows: @builder.rows.map { |row| row.map { |v| format_value(v) } }
  )
  table.to_s
end