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.



290
291
292
# File 'lib/term_utils/tab.rb', line 290

def initialize(opts = {})
  @tables = {}
end

Instance Attribute Details

#tablesHash<Symbol, Tab::Table>

Returns:



289
290
291
# File 'lib/term_utils/tab.rb', line 289

def tables
  @tables
end

Instance Method Details

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

Defines a table.

Parameters:

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

Returns:



297
298
299
300
301
302
303
304
305
306
307
# File 'lib/term_utils/tab.rb', line 297

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



311
312
313
# File 'lib/term_utils/tab.rb', line 311

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:



321
322
323
# File 'lib/term_utils/tab.rb', line 321

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