Class: TermUtils::Tab::Holder

Inherits:
Object
  • Object
show all
Defined in:
lib/term_utils/tab.rb

Overview

Represents a holder of tables.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Holder

Returns a new instance of Holder



421
422
423
424
425
# File 'lib/term_utils/tab.rb', line 421

def initialize(opts = {})
  @table_defaults = TermUtils::Tab.init_table_props
  @column_defaults = TermUtils::Tab.init_column_props
  @tables = {}
end

Instance Attribute Details

#column_defaultsHash

Returns `:width`, `:align`, `:fixed`, `:ellipsis`, `:format`.

Returns:

  • (Hash)

    `:width`, `:align`, `:fixed`, `:ellipsis`, `:format`.



418
419
420
# File 'lib/term_utils/tab.rb', line 418

def column_defaults
  @column_defaults
end

#table_defaultsHash

Returns `:offset`, `:column_separator_width`.

Returns:

  • (Hash)

    `:offset`, `:column_separator_width`.



416
417
418
# File 'lib/term_utils/tab.rb', line 416

def table_defaults
  @table_defaults
end

#tablesHash<Symbol, Tab::Table>

Returns:



420
421
422
# File 'lib/term_utils/tab.rb', line 420

def tables
  @tables
end

Instance Method Details

#create_table(opts = {}, &block) ⇒ Tab::Table

Creates a new table, using default properties, without registering it.

Parameters:

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

Returns:



446
447
448
449
450
451
452
453
# File 'lib/term_utils/tab.rb', line 446

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) if block
  new_tab
end

#define_table(id, opts = {}, &block) ⇒ Tab::Table

Defines a table, using default properties.

Parameters:

  • id (Symbol)
  • opts (Hash) (defaults to: {})

Returns:



458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/term_utils/tab.rb', line 458

def define_table(id, opts = {}, &block)
  if @tables.has_key? id
    block.call(@tables[id]) if block
  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) if block
    @tables[id] = new_tab
  end
  @tables[id]
end

#find_table(id) ⇒ Tab::Table?

Finds a table.

Parameters:

  • id (Symbol)

Returns:



475
476
477
# File 'lib/term_utils/tab.rb', line 475

def find_table(id)
  @tables[id]
end

#printer(id, io, opts = {}, &block) ⇒ Tab::Printer

Creates a new table printer.

Parameters:

  • id (Symbol)
  • io (IO)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :offset (Integer)
  • :column_separator_width (Integer)

Returns:



485
486
487
# File 'lib/term_utils/tab.rb', line 485

def printer(id, io, opts = {}, &block)
  find_table(id).printer(io, opts, &block)
end

#set_column_defaults(opts = {}) ⇒ Object

Sets column default properties.

Parameters:

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

Options Hash (opts):

  • :width (Integer)
  • :align (Symbol)
  • :fixed (Boolean)
  • :ellipsis (String)
  • :format (Proc, String, nil)


440
441
442
# File 'lib/term_utils/tab.rb', line 440

def set_column_defaults(opts = {})
  TermUtils::Tab.assign_column_props(@column_defaults, opts)
end

#set_table_defaults(opts = {}) ⇒ Object

Sets table default properties.

Parameters:

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

Options Hash (opts):

  • :offset (Integer)
  • :column_separator_width (Symbol)


430
431
432
# File 'lib/term_utils/tab.rb', line 430

def set_table_defaults(opts = {})
  TermUtils::Tab.assign_table_props(@table_defaults, opts)
end