Class: PProf::OutputFormatter::ASCIITable

Inherits:
Object
  • Object
show all
Defined in:
lib/pprof/output_formatter.rb

Overview

A small helper to print ASCII tables

Instance Method Summary collapse

Constructor Details

#initialize(*widths) ⇒ ASCIITable

Create a new ASCII table

Parameters:

  • widths (Int...)

    The list of width for each colum of the table



21
22
23
# File 'lib/pprof/output_formatter.rb', line 21

def initialize(*widths)
  @widths = widths
end

Instance Method Details

#row(*cols) ⇒ Object

Add a new row to the ASCII table

Parameters:

  • cols (String...)

    The content of each column of the row to add



29
30
31
32
33
# File 'lib/pprof/output_formatter.rb', line 29

def row(*cols)
  '| ' + cols.zip(@widths).map do |c,w|
    (c || '<nil>').to_s.ljust(w)[0...w]
  end.join(' | ') + ' |'
end

#separatorObject

Add a separator line to the ASCII table



36
37
38
# File 'lib/pprof/output_formatter.rb', line 36

def separator
  '+' + @widths.map { |w| '-' * (w+2) }.join('+') + '+' 
end