Class: TTY::Table::Orientation::Horizontal
- Inherits:
-
TTY::Table::Orientation
- Object
- TTY::Table::Orientation
- TTY::Table::Orientation::Horizontal
- Defined in:
- lib/tty/table/orientation/horizontal.rb
Overview
A class responsible for horizontal table transformation
Instance Attribute Summary
Attributes inherited from TTY::Table::Orientation
Instance Method Summary collapse
-
#slice(table) ⇒ Object
Slice vertical table data into horizontal.
-
#transform(table) ⇒ nil
Rotate table horizontally.
Methods inherited from TTY::Table::Orientation
coerce, #horizontal?, #initialize, #vertical?
Constructor Details
This class inherits a constructor from TTY::Table::Orientation
Instance Method Details
#slice(table) ⇒ Object
Slice vertical table data into horizontal
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tty/table/orientation/horizontal.rb', line 25 def slice(table) head, body, array_h, array_b = 4.times.map { [] } index = 0 first_column = 0 second_column = 1 (0...table.original_columns * table.original_rows).each do |col_index| row = table.rows[index] array_h += [row[first_column]] array_b += [row[second_column]] if col_index % table.original_columns == 2 head << array_h body << array_b array_h, array_b = [], [] end index += 1 end [head, body] end |
#transform(table) ⇒ nil
Rotate table horizontally
16 17 18 |
# File 'lib/tty/table/orientation/horizontal.rb', line 16 def transform(table) table.rotate_horizontal end |