Class: TTY::Table::Renderer::Basic Private
- Inherits:
-
Object
- Object
- TTY::Table::Renderer::Basic
- Includes:
- Validatable
- Defined in:
- lib/tty/table/renderer/basic.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Renders table without any border styles.
Instance Attribute Summary collapse
-
#border_class ⇒ TTY::Table::Border
private
Table border to be rendered.
-
#column_aligns ⇒ Array
private
The table column alignments.
-
#column_widths ⇒ Array[Integer]
Parses supplied column widths, if not present calculates natural widths.
-
#filter ⇒ Object
A callable object used for formatting field content.
-
#indent ⇒ Integer
The table indentation value.
-
#multiline ⇒ Boolean
The table column span behaviour.
-
#operations ⇒ Object
readonly
The table operations applied to rows.
-
#padding ⇒ TTY::Table::Padder
The table padding settings.
-
#resize ⇒ Integer
The table resizing behaviour.
-
#table ⇒ TTY::Table
readonly
Table to be rendered.
-
#width ⇒ Integer
The table totabl width.
Instance Method Summary collapse
-
#add_operations ⇒ Object
private
Initialize and add operations.
-
#border(options = (not_set=true)) {|Table::BorderOptions| ... } ⇒ Object
Store border characters, style and separator for the table rendering.
-
#columns_constraints ⇒ Object
private
Return column contraints.
-
#indentation ⇒ TTY::Table::Indentation
private
Initializes indentation.
-
#initialize(table, options = {}) ⇒ TTY::Table::Renderer::Basic
constructor
private
Initialize a Renderer.
-
#insert_indent(line) ⇒ Object
Delegate indentation insertion.
-
#render ⇒ String
Renders table.
Methods included from Validatable
#assert_row_sizes, #assert_table_type, #validate_options!
Constructor Details
#initialize(table, options = {}) ⇒ TTY::Table::Renderer::Basic
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.
Initialize a Renderer
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/tty/table/renderer/basic.rb', line 106 def initialize(table, = {}) @table = assert_table_type(table) @multiline = .fetch(:multiline) { false } @operations = TTY::Table::Operations.new(table) @operations.add(:escape, Operation::Escape.new) @border = TTY::Table::BorderOptions.from(.delete(:border)) @column_widths = .fetch(:column_widths, nil) @column_aligns = Array(.delete(:column_aligns)).map(&:to_sym) @filter = .fetch(:filter) { proc { |val, _| val } } @width = .fetch(:width) { TTY.terminal.width } @border_class = .fetch(:border_class) { Border::Null } @indent = .fetch(:indent) { 0 } @resize = .fetch(:resize) { false } @padding = TTY::Table::Padder.parse([:padding]) end |
Instance Attribute Details
#border_class ⇒ TTY::Table::Border
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
27 28 29 |
# File 'lib/tty/table/renderer/basic.rb', line 27 def border_class @border_class end |
#column_aligns ⇒ Array
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.
The table column alignments
41 42 43 |
# File 'lib/tty/table/renderer/basic.rb', line 41 def column_aligns @column_aligns end |
#column_widths ⇒ Array[Integer]
Parses supplied column widths, if not present calculates natural widths.
128 129 130 |
# File 'lib/tty/table/renderer/basic.rb', line 128 def column_widths @column_widths = ColumnSet.widths_from(table, @column_widths) end |
#filter ⇒ Object
A callable object used for formatting field content
51 52 53 |
# File 'lib/tty/table/renderer/basic.rb', line 51 def filter @filter end |
#indent ⇒ Integer
The table indentation value
66 67 68 |
# File 'lib/tty/table/renderer/basic.rb', line 66 def indent @indent end |
#multiline ⇒ Boolean
The table column span behaviour. When true the column’s line breaks cause the column to span multiple rows. By default set to false.
59 60 61 |
# File 'lib/tty/table/renderer/basic.rb', line 59 def multiline @multiline end |
#operations ⇒ Object (readonly)
The table operations applied to rows
46 47 48 |
# File 'lib/tty/table/renderer/basic.rb', line 46 def operations @operations end |
#padding ⇒ TTY::Table::Padder
The table padding settings
89 90 91 |
# File 'lib/tty/table/renderer/basic.rb', line 89 def padding @padding end |
#resize ⇒ Integer
The table resizing behaviour. If true the algorithm will automatically expand or shrink table to fit the terminal width or specified width. By default its false.
82 83 84 |
# File 'lib/tty/table/renderer/basic.rb', line 82 def resize @resize end |
#table ⇒ TTY::Table (readonly)
Table to be rendered
19 20 21 |
# File 'lib/tty/table/renderer/basic.rb', line 19 def table @table end |
#width ⇒ Integer
The table totabl width
73 74 75 |
# File 'lib/tty/table/renderer/basic.rb', line 73 def width @width end |
Instance Method Details
#add_operations ⇒ Object
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.
Initialize and add operations
154 155 156 157 158 159 160 161 |
# File 'lib/tty/table/renderer/basic.rb', line 154 def add_operations operations.add(:alignment, Operation::AlignmentSet.new(column_aligns, column_widths)) operations.add(:filter, Operation::Filter.new(filter)) operations.add(:truncation, Operation::Truncation.new(column_widths)) operations.add(:wrapping, Operation::Wrapped.new(column_widths, padding)) operations.add(:padding, Operation::Padding.new(padding, multiline)) end |
#border(options = (not_set=true)) {|Table::BorderOptions| ... } ⇒ Object
Store border characters, style and separator for the table rendering
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/tty/table/renderer/basic.rb', line 140 def border(=(not_set=true), &block) @border = TTY::Table::BorderOptions.new unless @border if block_given? border_dsl = TTY::Table::BorderDSL.new(&block) @border = border_dsl. elsif !not_set @border = TTY::Table::BorderOptions.from() end @border end |
#columns_constraints ⇒ Object
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.
Return column contraints
182 183 184 |
# File 'lib/tty/table/renderer/basic.rb', line 182 def columns_constraints TTY::Table::Columns.new(self) end |
#indentation ⇒ TTY::Table::Indentation
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.
Initializes indentation
168 169 170 |
# File 'lib/tty/table/renderer/basic.rb', line 168 def indentation @indentation ||= TTY::Table::Indentation.new(self) end |
#insert_indent(line) ⇒ Object
Delegate indentation insertion
175 176 177 |
# File 'lib/tty/table/renderer/basic.rb', line 175 def insert_indent(line) indentation.insert_indent(line) end |
#render ⇒ String
Renders table
201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/tty/table/renderer/basic.rb', line 201 def render return if table.empty? operations.run_operations(:escape) unless multiline columns_constraints.enforce add_operations ops = [:alignment] ops << :padding unless padding.empty? multiline ? ops << :wrapping : ops << :truncation ops << :filter operations.run_operations(*ops) render_data.compact.join("\n") end |