Class: PrimeTest::TerminalTable
- Inherits:
-
Object
- Object
- PrimeTest::TerminalTable
- Defined in:
- lib/prime_test/terminal_table.rb
Instance Attribute Summary collapse
-
#table_data ⇒ Object
readonly
Returns the value of attribute table_data.
Instance Method Summary collapse
-
#initialize(table_data) ⇒ TerminalTable
constructor
A new instance of TerminalTable.
- #rows ⇒ Object
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_data ⇒ Object (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
#rows ⇒ Object
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 |