Class: TTY::Table::Renderer Private
- Inherits:
-
Object
- Object
- TTY::Table::Renderer
- Defined in:
- lib/tty/table/renderer.rb,
lib/tty/table/renderer/ascii.rb,
lib/tty/table/renderer/basic.rb,
lib/tty/table/renderer/color.rb,
lib/tty/table/renderer/unicode.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.
A class responsible for rendering tabular data
Used internally by TTY::Table to render table content out.
Defined Under Namespace
Classes: ASCII, Basic, Color, Unicode
Constant Summary collapse
- RENDERER_MAPPER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ ascii: TTY::Table::Renderer::ASCII, basic: TTY::Table::Renderer::Basic, color: TTY::Table::Renderer::Color, unicode: TTY::Table::Renderer::Unicode }
Class Method Summary collapse
-
.assert_border_class(border_class) ⇒ Object
Raises an error if provided border class is of wrong type or has invalid implementation.
-
.render(table, options = {}) {|renderer| ... } ⇒ String
Render a given table and return the string representation.
-
.render_with(border_class, table, options = {}, &block) ⇒ Object
Add custom border for the renderer.
-
.select(type) ⇒ TTY::Table::Renderer
private
Select renderer class based on string name.
Class Method Details
.assert_border_class(border_class) ⇒ Object
Raises an error if provided border class is of wrong type or has invalid implementation
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tty/table/renderer.rb', line 48 def self.assert_border_class(border_class) return unless border_class unless border_class <= TTY::Table::Border fail TypeError, "#{border_class} should inherit from TTY::Table::Border" end unless border_class.characters fail NoImplementationError, "#{border_class} should implement def_border" end end |
.render(table, options = {}) {|renderer| ... } ⇒ String
Render a given table and return the string representation.
94 95 96 97 98 |
# File 'lib/tty/table/renderer.rb', line 94 def self.render(table, = {}, &block) renderer = select([:renderer]).new(table, ) yield renderer if block_given? renderer.render end |
.render_with(border_class, table, options = {}, &block) ⇒ Object
Add custom border for the renderer
75 76 77 78 79 |
# File 'lib/tty/table/renderer.rb', line 75 def self.render_with(border_class, table, = {}, &block) assert_border_class(border_class) [:border_class] = border_class if border_class render(table, , &block) end |
.select(type) ⇒ TTY::Table::Renderer
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.
Select renderer class based on string name.
The possible values for renderer are
- :basic, :ascii, :unicode, :color
34 35 36 |
# File 'lib/tty/table/renderer.rb', line 34 def self.select(type) RENDERER_MAPPER[type || :basic] end |