Class: PProf::OutputFormatter::ASCIITable
- Inherits:
-
Object
- Object
- PProf::OutputFormatter::ASCIITable
- Defined in:
- lib/pprof/output_formatter.rb
Overview
A small helper to print ASCII tables
Instance Method Summary collapse
-
#initialize(*widths) ⇒ ASCIITable
constructor
Create a new ASCII table.
-
#row(*cols) ⇒ Object
Add a new row to the ASCII table.
-
#separator ⇒ Object
Add a separator line to the ASCII table.
Constructor Details
#initialize(*widths) ⇒ ASCIITable
Create a new ASCII 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
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 |
#separator ⇒ Object
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 |