Sha256: 24a14b69f22635ce9da8010ba71e7f6f7867b50cd0e49fc294c97f2426a8f65c

Contents?: true

Size: 951 Bytes

Versions: 9

Compression:

Stored size: 951 Bytes

Contents

# encoding: utf-8

module TTY
  class Table
    # A class representing table orientation
    class Orientation
      # A class responsible for vertical table transformation
      class Vertical < Orientation
        # Rotate table vertically
        #
        # @param [Table] table
        #
        # @return [nil]
        #
        # @api public
        def transform(table)
          table.rotate_vertical
        end

        # Slice horizontal table data into vertical
        #
        # @param [Table] table
        #
        # @api public
        def slice(table)
          header    = table.header
          rows_size = table.rows_size

          head = header ? header : (0..rows_size).map { |n| (n + 1).to_s }

          (0...rows_size).reduce([]) do |array, index|
            array + head.zip(table.rows[index]).map { |row| table.to_row(row) }
          end
        end
      end # Vertical
    end # Orientation
  end # Table
end # TTY

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tty-table-0.10.0 lib/tty/table/orientation/vertical.rb
tty-table-0.9.0 lib/tty/table/orientation/vertical.rb
tty-table-0.8.0 lib/tty/table/orientation/vertical.rb
tty-table-0.7.0 lib/tty/table/orientation/vertical.rb
tty-table-0.6.0 lib/tty/table/orientation/vertical.rb
tty-table-0.5.0 lib/tty/table/orientation/vertical.rb
tty-table-0.4.0 lib/tty/table/orientation/vertical.rb
tty-table-0.3.0 lib/tty/table/orientation/vertical.rb
tty-table-0.2.0 lib/tty/table/orientation/vertical.rb