class Supercop::TableFormatter

Constants

CELL_WIDTH
DEFAULT_COLUMNS

Public Class Methods

new(columns = nil) click to toggle source
# File lib/supercop/table_formatter.rb, line 6
def initialize(columns = nil)
  @columns = columns || DEFAULT_COLUMNS
end

Public Instance Methods

print_table(lines) click to toggle source

Private Instance Methods

cell(word) click to toggle source
# File lib/supercop/table_formatter.rb, line 38
def cell(word)
  word.center(word.length + (CELL_WIDTH - word.length).abs) + '|'
end
dash_line() click to toggle source
# File lib/supercop/table_formatter.rb, line 24
def dash_line
  line = '+'
  @columns.count.times { line += Array.new(CELL_WIDTH, '-').join + '+' }
  line
end
header() click to toggle source
# File lib/supercop/table_formatter.rb, line 20
def header
  dash_line + "\n" + line(@columns) + "\n" + dash_line
end
line(elements) click to toggle source
# File lib/supercop/table_formatter.rb, line 34
def line(elements)
  '|' + elements.map { |element| cell(element.to_s) }.join
end