Class: TermUtils::Tab::Printer

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

Overview

Represents a table printer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, io, options) ⇒ Printer

Returns a new instance of Printer.

Parameters:



402
403
404
405
406
# File 'lib/term_utils/tab.rb', line 402

def initialize(table, io, options)
  @table = table
  @io = io
  @options = options
end

Instance Attribute Details

#ioIO

Returns:

  • (IO)


395
396
397
# File 'lib/term_utils/tab.rb', line 395

def io
  @io
end

#optionsHash

Returns:

  • (Hash)


397
398
399
# File 'lib/term_utils/tab.rb', line 397

def options
  @options
end

#tableTab::Table

Returns:



393
394
395
# File 'lib/term_utils/tab.rb', line 393

def table
  @table
end

Instance Method Details

#data(values, opts = nil) ⇒ nil

Prints a data row.

Parameters:

  • values (Array<Object>, Hash<Symbol, Object>)
  • opts (Hash) (defaults to: nil)

Options Hash (opts):

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

Returns:

  • (nil)


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

def data(values, opts = nil)
  @table.print_data(@io, values, opts ? @options.merge(opts) : @options)
end

#header(values = nil, opts = nil) ⇒ nil

Prints a header row.

Parameters:

  • values (Array<Object>, Hash<Symbol, Object>) (defaults to: nil)
  • opts (Hash) (defaults to: nil)

Options Hash (opts):

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

Returns:

  • (nil)


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

def header(values = nil, opts = nil)
  @table.print_header(@io, values, opts ? @options.merge(opts) : @options)
end

#lineObject

Prints an empty line.



409
410
411
# File 'lib/term_utils/tab.rb', line 409

def line
  @io.puts
end

#separator(opts = nil) ⇒ nil

Prints a separator.

Parameters:

  • opts (Hash) (defaults to: nil)

Options Hash (opts):

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

Returns:

  • (nil)


438
439
440
# File 'lib/term_utils/tab.rb', line 438

def separator(opts = nil)
  @table.print_separator(@io, opts ? @options.merge(opts) : @options)
end