Class: SportsManager::SolutionDrawer::CLI::Table
- Defined in:
- lib/sports_manager/solution_drawer/cli/table.rb
Overview
Public: creates a table based on a list of hashes containing the name of the columns and their values
Example: data = [
{ a: [1, 2, 3], b: 10_000, c: 'ABCDEFGHIJKLMNOP' },
{ a: [4, 5, 6, 7], b: 20_000_000, c: 'QRSTUVWXYZ' }
]
a | b | c
-------------|----------|-----------------
1, 2, 3 | 10000 | ABCDEFGHIJKLMNOP
4, 5, 6, 7 | 20000000 | QRSTUVWXYZ
Constant Summary collapse
- SECTION_SEPARATOR =
'-|-'- COLUMN_SEPARATOR =
' | '- ROW_SEPARATOR =
'-'
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(data) ⇒ Table
constructor
A new instance of Table.
Constructor Details
#initialize(data) ⇒ Table
Returns a new instance of Table.
30 31 32 |
# File 'lib/sports_manager/solution_drawer/cli/table.rb', line 30 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
20 21 22 |
# File 'lib/sports_manager/solution_drawer/cli/table.rb', line 20 def data @data end |
Class Method Details
.draw(data) ⇒ Object
26 27 28 |
# File 'lib/sports_manager/solution_drawer/cli/table.rb', line 26 def self.draw(data) new(data).draw end |
Instance Method Details
#draw ⇒ Object
34 35 36 |
# File 'lib/sports_manager/solution_drawer/cli/table.rb', line 34 def draw [header_row, separator, *content_rows].join("\n") end |