Module: TTY::Table::Columns Private
- Defined in:
- lib/greenhat/tty/columns.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
A module for calculating table data column widths
Used by TTY::Table to manage column sizing.
Class Method Summary collapse
-
.widths_from(table, column_widths = nil) ⇒ Array[Integer]
Converts column widths to array format or infers default widths.
Class Method Details
.widths_from(table, column_widths = nil) ⇒ Array[Integer]
Converts column widths to array format or infers default widths
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/greenhat/tty/columns.rb', line 20 def widths_from(table, column_widths = nil) case column_widths when Array assert_widths(column_widths, table.columns_size) Array(column_widths).map(&:to_i) when Numeric Array.new(table.columns_size, column_widths) when NilClass # THE SHIM! Strings that are too large fail to render correctly to do an empty result # Set the maximum table width to half the screen size. Can't be full size due to the table headers LogBot.debug('TTY Column Width') if ENV['DEBUG'] # TODO: Check Empty Results return [0] if table.data.empty? extract_widths(table.data).map { |x| x >= TTY::Screen.width ? (TTY::Screen.width * 3 / 4) : x } else raise TypeError, 'Invalid type for column widths' end end |