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:



250
251
252
253
254
# File 'lib/term_utils/tab.rb', line 250

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

Instance Attribute Details

#ioIO

Returns:

  • (IO)


244
245
246
# File 'lib/term_utils/tab.rb', line 244

def io
  @io
end

#optionsHash

Returns:

  • (Hash)


246
247
248
# File 'lib/term_utils/tab.rb', line 246

def options
  @options
end

#tableTab::Table

Returns:



242
243
244
# File 'lib/term_utils/tab.rb', line 242

def table
  @table
end

Instance Method Details

#data(values, opts = {}) ⇒ nil

Prints a data row.

Parameters:

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

Options Hash (opts):

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

Returns:

  • (nil)


274
275
276
# File 'lib/term_utils/tab.rb', line 274

def data(values, opts = {})
  @table.print_data(@io, values, @options.merge(opts))
end

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

Prints a header row.

Parameters:

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

Options Hash (opts):

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

Returns:

  • (nil)


265
266
267
# File 'lib/term_utils/tab.rb', line 265

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

#lineObject

Prints an empty line.



256
257
258
# File 'lib/term_utils/tab.rb', line 256

def line
  @io.puts ""
end

#separator(opts = {}) ⇒ nil

Prints a separator.

Parameters:

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

Options Hash (opts):

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

Returns:

  • (nil)


282
283
284
# File 'lib/term_utils/tab.rb', line 282

def separator(opts = {})
  @table.print_separator(@io, @options.merge(opts))
end