class TermUtils::Tab::Holder

Represents a Holder of Table(s).

Attributes

column_defaults[RW]

@return [Hash] `:width`, `:align`, `:fixed`, `:ellipsis`, `:format`.

table_defaults[RW]

@return [Hash] `:offset`, `:column_separator_width`.

tables[RW]

@return [Hash<Symbol, Tab::Table>]

Public Class Methods

new() click to toggle source

Creates a new Holder.

# File lib/term_utils/tab.rb, line 452
def initialize
  @table_defaults = TermUtils::Tab.init_table_props
  @column_defaults = TermUtils::Tab.init_column_props
  @tables = {}
end

Public Instance Methods

create_table(opts = {}, &block) click to toggle source

Creates a new table, using default properties, without registering it. @param opts [Hash] @return [Tab::Table]

# File lib/term_utils/tab.rb, line 480
def create_table(opts = {}, &block)
  opts[:offset] = @table_defaults.fetch(:offset)
  opts[:column_separator_width] = @table_defaults.fetch(:column_separator_width)
  opts[:column_defaults] = @column_defaults.dup
  new_tab = Table.new(opts)
  block&.call(new_tab)
  new_tab
end
define_table(id, opts = {}, &block) click to toggle source

Defines a table, using default properties. @param id [Symbol] @param opts [Hash] @return [Tab::Table]

# File lib/term_utils/tab.rb, line 493
def define_table(id, opts = {}, &block)
  if @tables.key? id
    block&.call(@tables[id])
  else
    opts[:id] = id
    opts[:offset] = @table_defaults.fetch(:offset)
    opts[:column_separator_width] = @table_defaults.fetch(:column_separator_width)
    opts[:column_defaults] = @column_defaults.dup
    new_tab = Table.new(opts)
    block&.call(new_tab)
    @tables[id] = new_tab
  end
  @tables[id]
end
find_table(id) click to toggle source

Finds a table. @param id [Symbol] @return [Tab::Table, nil]

# File lib/term_utils/tab.rb, line 511
def find_table(id)
  @tables[id]
end
printer(id, io, opts = {}, &block) click to toggle source

Creates a new table printer. @param id [Symbol] @param io [IO] @param opts [Hash] @option opts [Integer] :offset @option opts [Integer] :column_separator_width @return [Tab::Printer]

# File lib/term_utils/tab.rb, line 522
def printer(id, io, opts = {}, &block)
  find_table(id).printer(io, opts, &block)
end
set_column_defaults(opts = {}) click to toggle source

Sets column default properties. @param opts [Hash] @option opts [Integer] :width @option opts [Symbol] :align @option opts [Boolean] :fixed @option opts [String] :ellipsis @option opts [Proc, String, nil] :format

# File lib/term_utils/tab.rb, line 473
def set_column_defaults(opts = {})
  TermUtils::Tab.assign_column_props(@column_defaults, opts)
end
set_table_defaults(opts = {}) click to toggle source

Sets table default properties. @param opts [Hash] @option opts [Integer] :offset @option opts [Symbol] :column_separator_width

# File lib/term_utils/tab.rb, line 462
def set_table_defaults(opts = {})
  TermUtils::Tab.assign_table_props(@table_defaults, opts)
end