Class: Terminal::Table::Row
- Inherits:
-
Object
- Object
- Terminal::Table::Row
- Defined in:
- lib/terminal-table/row.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cells ⇒ Object
readonly
Row cells.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #add_cell(item) ⇒ Object (also: #<<)
-
#crossings ⇒ Object
used to find indices where we have table ‘+’ crossings.
- #height ⇒ Object
-
#initialize(table, array = [], **_kwargs) ⇒ Row
constructor
Initialize with width and options.
- #number_of_columns ⇒ Object
- #render ⇒ Object
Constructor Details
Instance Attribute Details
#cells ⇒ Object (readonly)
Row cells
8 9 10 |
# File 'lib/terminal-table/row.rb', line 8 def cells @cells end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
10 11 12 |
# File 'lib/terminal-table/row.rb', line 10 def table @table end |
Instance Method Details
#[](index) ⇒ Object
30 31 32 |
# File 'lib/terminal-table/row.rb', line 30 def [] index cells[index] end |
#add_cell(item) ⇒ Object Also known as: <<
22 23 24 25 26 27 |
# File 'lib/terminal-table/row.rb', line 22 def add_cell item = item.is_a?(Hash) ? item : {:value => item} cell = Cell.new(.merge(:index => @cell_index, :table => @table)) @cell_index += cell.colspan @cells << cell end |
#crossings ⇒ Object
used to find indices where we have table ‘+’ crossings. in cases where the colspan > 1, then we will skip over some numbers if colspan is always 1, then the list should be incrementing by 1.
skip 0 entry, because it’s the left side. skip last entry, because it’s the right side. we only care about “+/T” style crossings.
58 59 60 61 |
# File 'lib/terminal-table/row.rb', line 58 def crossings idx = 0 @cells[0...-1].map { |c| idx += c.colspan } end |
#height ⇒ Object
34 35 36 |
# File 'lib/terminal-table/row.rb', line 34 def height cells.map { |c| c.lines.count }.max || 0 end |
#number_of_columns ⇒ Object
47 48 49 |
# File 'lib/terminal-table/row.rb', line 47 def number_of_columns @cells.collect(&:colspan).inject(0, &:+) end |
#render ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/terminal-table/row.rb', line 38 def render vleft, vcenter, vright = @table.style.vertical (0...height).to_a.map do |line| vleft + cells.map do |cell| cell.render(line) end.join(vcenter) + vright end.join("\n") end |