Class: TermUtils::Tab::Holder
- Inherits:
-
Object
- Object
- TermUtils::Tab::Holder
- Defined in:
- lib/term_utils/tab.rb
Overview
Represents a Holder of Table(s).
Instance Attribute Summary collapse
-
#column_defaults ⇒ Hash
`:width`, `:align`, `:fixed`, `:ellipsis`, `:format`.
-
#table_defaults ⇒ Hash
`:offset`, `:column_separator_width`.
- #tables ⇒ Hash<Symbol, Tab::Table>
Instance Method Summary collapse
-
#create_table(opts = {}, &block) ⇒ Tab::Table
Creates a new table, using default properties, without registering it.
-
#define_table(id, opts = {}, &block) ⇒ Tab::Table
Defines a table, using default properties.
-
#find_table(id) ⇒ Tab::Table?
Finds a table.
-
#initialize ⇒ Holder
constructor
Creates a new Holder.
-
#printer(id, io, opts = {}, &block) ⇒ Tab::Printer
Creates a new table printer.
-
#set_column_defaults(opts = {}) ⇒ Object
Sets column default properties.
-
#set_table_defaults(opts = {}) ⇒ Object
Sets table default properties.
Constructor Details
#initialize ⇒ Holder
Creates a new Holder.
452 453 454 455 456 |
# 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 |
Instance Attribute Details
#column_defaults ⇒ Hash
Returns `:width`, `:align`, `:fixed`, `:ellipsis`, `:format`.
447 448 449 |
# File 'lib/term_utils/tab.rb', line 447 def column_defaults @column_defaults end |
#table_defaults ⇒ Hash
Returns `:offset`, `:column_separator_width`.
445 446 447 |
# File 'lib/term_utils/tab.rb', line 445 def table_defaults @table_defaults end |
#tables ⇒ Hash<Symbol, Tab::Table>
449 450 451 |
# File 'lib/term_utils/tab.rb', line 449 def tables @tables end |
Instance Method Details
#create_table(opts = {}, &block) ⇒ Tab::Table
Creates a new table, using default properties, without registering it.
480 481 482 483 484 485 486 487 |
# 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) ⇒ Tab::Table
Defines a table, using default properties.
493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
# 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) ⇒ Tab::Table?
Finds a table.
511 512 513 |
# File 'lib/term_utils/tab.rb', line 511 def find_table(id) @tables[id] end |
#printer(id, io, opts = {}, &block) ⇒ Tab::Printer
Creates a new table printer.
522 523 524 |
# 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 = {}) ⇒ Object
Sets column default properties.
473 474 475 |
# 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 = {}) ⇒ Object
Sets table default properties.
462 463 464 |
# File 'lib/term_utils/tab.rb', line 462 def set_table_defaults(opts = {}) TermUtils::Tab.assign_table_props(@table_defaults, opts) end |