Method: TTY::Table::Renderer::Basic#render

Defined in:
lib/tty/table/renderer/basic.rb

#renderString

Renders table as string with border

Examples:

renderer = TTY::Table::Renderer::Basic.new(table)
renderer.render

Returns:

  • (String)

    the string representation of table



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/tty/table/renderer/basic.rb', line 186

def render
  return if table.empty?

  operations = TTY::Table::Operations.new
  operations.add(:escape, Operation::Escape.new)
  operations.apply_to(table, :escape) unless multiline

  column_constraint = ColumnConstraint.new(table, self)
  @column_widths = column_constraint.enforce
  widths_without_padding = @column_widths.map do |_width|
                            _width - padding.left - padding.right
                          end
  create_operations(widths_without_padding).each do |op|
    operations.add(*op)
  end
  operations.apply_to(table, *select_operations)

  render_data.compact.join("\n")
end