Method: TTY::Table::Renderer::Basic#initialize

Defined in:
lib/tty/table/renderer/basic.rb

#initialize(table, options = {}) ⇒ TTY::Table::Renderer::Basic

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a Renderer

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :alignments (String)

    used to format table individual column alignment

  • :border (Hash[Symbol])

    the border options

  • :column_widths (String)

    used to format table individula column width

  • :indent (Integer)

    indent the first column by indent value

  • :padding (Integer, Array)

    add padding to table fields

[View source]

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/tty/table/renderer/basic.rb', line 112

def initialize(table, options = {})
  @table         = assert_table_type(table)
  @multiline     = options.fetch(:multiline) { false }
  @border        = BorderDSL.new(options.delete(:border)).options
  unless @table.separators.empty?
    @border.separator ||= @table.separators
  end
  @column_widths = options.fetch(:column_widths, nil)
  alignment      = Array(options[:alignment]) * table.columns_size
  @alignments    = AlignmentSet.new(options[:alignments] || alignment)
  @filter        = options.fetch(:filter) { proc { |val, _| val } }
  @width         = options.fetch(:width) { TTY::Screen.width }
  @border_class  = options.fetch(:border_class) { Border::Null }
  @indent        = options.fetch(:indent) { 0 }
  @resize        = options.fetch(:resize) { false }
  @padding       = Strings::Padder.parse(options[:padding])
end