Class: QAT::Reporter::Helpers::AsciiTable
- Inherits:
-
Object
- Object
- QAT::Reporter::Helpers::AsciiTable
- Defined in:
- lib/qat/reporter/helpers/ascii_table.rb
Overview
Namespace for AsciiTable formatter
Instance Attribute Summary collapse
- #content ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(content) ⇒ AsciiTable
constructor
A new instance of AsciiTable.
- #to_s ⇒ Object
Constructor Details
#initialize(content) ⇒ AsciiTable
Returns a new instance of AsciiTable.
12 13 14 |
# File 'lib/qat/reporter/helpers/ascii_table.rb', line 12 def initialize(content) @content = content end |
Instance Attribute Details
#content ⇒ Object (readonly)
10 11 12 |
# File 'lib/qat/reporter/helpers/ascii_table.rb', line 10 def content @content end |
Instance Method Details
#to_s ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/qat/reporter/helpers/ascii_table.rb', line 16 def to_s return @ascii if @ascii # conver to 2D array table = set_table(content) widths = calculate_widths(table) # header separator table.insert(1, widths.map { |n| '-' * n }) format = widths.collect { |n| "%-#{n}s" }.join(" | ") @ascii ||= table.map do |line| sprintf "| #{format} |\n", *line end.join end |