Class: QAT::Reporter::Helpers::AsciiTable

Inherits:
Object
  • Object
show all
Defined in:
lib/qat/reporter/helpers/ascii_table.rb

Overview

Namespace for AsciiTable formatter

Since:

  • 6.1.7

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ AsciiTable

Returns a new instance of AsciiTable.

Since:

  • 6.1.7



12
13
14
# File 'lib/qat/reporter/helpers/ascii_table.rb', line 12

def initialize(content)
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Since:

  • 6.1.7



10
11
12
# File 'lib/qat/reporter/helpers/ascii_table.rb', line 10

def content
  @content
end

Instance Method Details

#to_sObject

Since:

  • 6.1.7



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