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:



377
378
379
380
381
# File 'lib/term_utils/tab.rb', line 377

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

Instance Attribute Details

#ioIO

Returns:

  • (IO)


371
372
373
# File 'lib/term_utils/tab.rb', line 371

def io
  @io
end

#optionsHash

Returns:

  • (Hash)


373
374
375
# File 'lib/term_utils/tab.rb', line 373

def options
  @options
end

#tableTab::Table

Returns:



369
370
371
# File 'lib/term_utils/tab.rb', line 369

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)


401
402
403
# File 'lib/term_utils/tab.rb', line 401

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)


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

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

#lineObject

Prints an empty line.



383
384
385
# File 'lib/term_utils/tab.rb', line 383

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)


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

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