Class: TTY::Table::Renderer::Basic

Inherits:
Object
  • Object
show all
Extended by:
Delegatable
Defined in:
lib/tty/table/renderer/basic.rb

Overview

Renders table without any border styles.

Direct Known Subclasses

ASCII, Color, Unicode

Constant Summary collapse

TABLE_DELEGATED_METHODS =
[:column_widths, :alignments]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Delegatable

delegatable_method

Constructor Details

#initialize(options = {}) ⇒ Table::Renderer::Basic

Initialize and setup a Renderer

Parameters:

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

    :indent - Indent the first column by indent value :padding - Pad out the row cell by padding value



49
50
51
# File 'lib/tty/table/renderer/basic.rb', line 49

def initialize(options={})
  setup(options)
end

Instance Attribute Details

#border_classTTY::Table::Border (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Table border to be rendered

Returns:



28
29
30
# File 'lib/tty/table/renderer/basic.rb', line 28

def border_class
  @border_class
end

#indentObject (readonly)



13
14
15
# File 'lib/tty/table/renderer/basic.rb', line 13

def indent
  @indent
end

#paddingObject



11
12
13
# File 'lib/tty/table/renderer/basic.rb', line 11

def padding
  @padding
end

#tableTTY::Table (readonly)

Table to be rendered

Returns:



20
21
22
# File 'lib/tty/table/renderer/basic.rb', line 20

def table
  @table
end

Class Method Details

.render(table, options = {}) ⇒ Object



76
77
78
# File 'lib/tty/table/renderer/basic.rb', line 76

def self.render(table, options={})
  new(options).render(table)
end

Instance Method Details

#render(table, border_class = Border::Null) ⇒ String

Renders table

Parameters:

Returns:

  • (String)

    string representation of table



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/tty/table/renderer/basic.rb', line 88

def render(table, border_class=Border::Null)
  @table = table
  @border_class = border_class

  return if table.to_a.empty?
  # setup(options)
  body = []
  unless table.length.zero?
    ColumnSet.new(table).extract_widths!
    # TODO: throw an error if too many columns as compared to terminal width
    # and then change table.orientation from vertical to horizontal
    # TODO: Decide about table orientation

    body += render_header
    body += render_rows
  end
  body.compact.join("\n")
end