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



28
29
30
# File 'lib/pprof/output_formatter.rb', line 28

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



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

def row(*cols)
  justified_cols = cols.zip(@widths).map do |c, w|
    (c || '<nil>').to_s.ljust(w)[0...w]
  end
  "| #{justified_cols.join(' | ')} |"
end

#separatorObject

Add a separator line to the ASCII table



44
45
46
47
# File 'lib/pprof/output_formatter.rb', line 44

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