Class: OutputMode::Outputs::Tabulated

Inherits:
OutputMode::Output show all
Defined in:
lib/output_mode/outputs/tabulated.rb

Instance Attribute Summary collapse

Attributes inherited from OutputMode::Output

#context, #procs

Instance Method Summary collapse

Methods inherited from OutputMode::Output

#callables, #generate

Constructor Details

#initialize(*procs, renderer: nil, **config) {|tty_table_renderer| ... } ⇒ Tabulated

Returns a new instance of Tabulated.

Parameters:

  • *procs (Array)

    see Base#initialize

  • :renderer (Symbol)

    override the default renderer

  • **config (Hash)

    additional options to the renderer

Yield Parameters:

  • tty_table_renderer (TTY::Table::Renderer::Base)

    optional access the underlining TTY::Table renderer



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/output_mode/outputs/tabulated.rb', line 54

def initialize(*procs,
               renderer: :unicode,
               colorize: false,
               header_color: nil,
               row_color: nil,
               **config,
               &block)
  @renderer =  renderer
  @block = block
  @header_color = header_color
  @row_color = row_color
  @colorize = colorize
  super(*procs, **config)
end

Instance Attribute Details

#block#call (readonly)

Returns an optional block of code that configures the renderer.

Returns:

  • (#call)

    an optional block of code that configures the renderer



42
43
# File 'lib/output_mode/outputs/tabulated.rb', line 42

attr_reader :renderer, :default, :block, :yes, :no,
:header_color, :row_color, :colorize

#colorizeObject (readonly)

Returns the value of attribute colorize.



42
43
# File 'lib/output_mode/outputs/tabulated.rb', line 42

attr_reader :renderer, :default, :block, :yes, :no,
:header_color, :row_color, :colorize

#defaultObject (readonly)

Returns the value of attribute default.



42
43
44
# File 'lib/output_mode/outputs/tabulated.rb', line 42

def default
  @default
end

#header_colorObject (readonly)

Returns An optional header color or array of colors.

Returns:

  • An optional header color or array of colors



42
43
# File 'lib/output_mode/outputs/tabulated.rb', line 42

attr_reader :renderer, :default, :block, :yes, :no,
:header_color, :row_color, :colorize

#noObject (readonly)

Returns the value of attribute no.



42
43
44
# File 'lib/output_mode/outputs/tabulated.rb', line 42

def no
  @no
end

#rendererSymbol (readonly)

Returns the renderer type, see: github.com/piotrmurach/tty-table#32-renderer.

Returns:



42
43
44
# File 'lib/output_mode/outputs/tabulated.rb', line 42

def renderer
  @renderer
end

#row_colorObject (readonly)

Returns An optional data color or array of colors.

Returns:

  • An optional data color or array of colors



42
43
# File 'lib/output_mode/outputs/tabulated.rb', line 42

attr_reader :renderer, :default, :block, :yes, :no,
:header_color, :row_color, :colorize

#yesObject (readonly)

Returns the value of attribute yes.



42
43
44
# File 'lib/output_mode/outputs/tabulated.rb', line 42

def yes
  @yes
end

Instance Method Details

#configHash

Returns additional options to TTY::Table renderer.

Returns:

  • (Hash)

    additional options to TTY::Table renderer

See Also:



47
# File 'lib/output_mode/outputs/tabulated.rb', line 47

def config; super; end

#render(*data) ⇒ Object

Implements the render method using TTY::Table



72
73
74
75
76
# File 'lib/output_mode/outputs/tabulated.rb', line 72

def render(*data)
  table = TTY::Table.new header: processed_header
  data.each { |d| table << process_row(d) }
  table.render(renderer, **config, &block) || ''
end