Class: KXI::CLI::Table::Column
- Inherits:
-
Object
- Object
- KXI::CLI::Table::Column
- Defined in:
- lib/kxi/cli/table.rb
Overview
Represents a column of table
Instance Method Summary collapse
-
#align ⇒ integer
Gets the length of the longest value.
-
#initialize(name) ⇒ Column
constructor
Instantiates the Column class.
-
#name ⇒ string
Gets the name of column.
-
#row(str) ⇒ Object
Adds a row to the column.
-
#write(row) ⇒ Object
Writes the value of a row at given index to stdout.
Constructor Details
#initialize(name) ⇒ Column
Instantiates the KXI::CLI::Table::Column class
60 61 62 63 64 |
# File 'lib/kxi/cli/table.rb', line 60 def initialize(name) @name = name @align = 0 @data = [] end |
Instance Method Details
#align ⇒ integer
Gets the length of the longest value
48 49 50 |
# File 'lib/kxi/cli/table.rb', line 48 def align @align end |
#name ⇒ string
Gets the name of column
54 55 56 |
# File 'lib/kxi/cli/table.rb', line 54 def name @name end |
#row(str) ⇒ Object
Adds a row to the column
68 69 70 71 |
# File 'lib/kxi/cli/table.rb', line 68 def row(str) @align = str.length if @align < str.length @data.push(str) end |
#write(row) ⇒ Object
Writes the value of a row at given index to stdout
75 76 77 78 79 |
# File 'lib/kxi/cli/table.rb', line 75 def write(row) str = @data[row] str = '' if str == nil print(str.ljust(@align)) end |