Sha256: 8c9f733fd70e997266fc4bc1aeb1313b40d7fa3776297ee074ccde472bcbb12f

Contents?: true

Size: 1.22 KB

Versions: 13

Compression:

Stored size: 1.22 KB

Contents

# encoding: utf-8

module TTY
  class Table
    # A class representing table orientation
    class Orientation
      # A class responsible for horizontal table transformation
      class Horizontal < Orientation
        # Rotate table horizontally
        #
        # @param [Table] table
        #
        # @return [nil]
        #
        # @api public
        def transform(table)
          table.rotate_horizontal
        end

        # Slice vertical table data into horizontal
        #
        # @param [Table] table
        #
        # @api public
        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
      end # Horizontal
    end # Orientation
  end # Table
end # TTY

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
tty-table-0.10.0 lib/tty/table/orientation/horizontal.rb
tty-table-0.9.0 lib/tty/table/orientation/horizontal.rb
tty-table-0.8.0 lib/tty/table/orientation/horizontal.rb
tty-table-0.7.0 lib/tty/table/orientation/horizontal.rb
tty-table-0.6.0 lib/tty/table/orientation/horizontal.rb
tty-table-0.5.0 lib/tty/table/orientation/horizontal.rb
tty-table-0.4.0 lib/tty/table/orientation/horizontal.rb
tty-table-0.3.0 lib/tty/table/orientation/horizontal.rb
tty-table-0.2.0 lib/tty/table/orientation/horizontal.rb
tty-table-0.1.0 lib/tty/table/orientation/horizontal.rb
tty-0.1.2 lib/tty/table/orientation/horizontal.rb
tty-0.1.1 lib/tty/table/orientation/horizontal.rb
tty-0.1.0 lib/tty/table/orientation/horizontal.rb