Class: PrimeTest::TerminalTable

Inherits:
Object
  • Object
show all
Defined in:
lib/prime_test/terminal_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_data) ⇒ TerminalTable

Returns a new instance of TerminalTable.



5
6
7
8
# File 'lib/prime_test/terminal_table.rb', line 5

def initialize(table_data)
  @table_data = table_data
  validate_data!
end

Instance Attribute Details

#table_dataObject (readonly)

Returns the value of attribute table_data.



4
5
6
# File 'lib/prime_test/terminal_table.rb', line 4

def table_data
  @table_data
end

Instance Method Details

#rowsObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/prime_test/terminal_table.rb', line 11

def rows
  max_size = table_data.flatten.map(&:to_s).max_by(&:length).size
  r = table_data.map do |row|
    '| ' + row.map {|x| format_cell(x, max_size) }.join(" | ") + ' |'
  end
  blank_row = "_" * r.first.size

  r.unshift(blank_row)
  r.push(blank_row)
end