Module: TTY::Table::Renderer Private
- Defined in:
- lib/tty/table/renderer.rb,
lib/tty/table/renderer/ascii.rb,
lib/tty/table/renderer/basic.rb,
lib/tty/table/renderer/unicode.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
A module responsible for selecting tabule data renderer
Used internally by TTY::Table to render table content out.
Defined Under Namespace
Classes: ASCII, Basic, 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, 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 assert_border_class(border_class) return unless border_class unless border_class <= TTY::Table::Border raise TypeError, "#{border_class} should inherit from TTY::Table::Border" end unless border_class.characters raise NoImplementationError, "#{border_class} should implement def_border" end end |
.render(table, options = {}) {|renderer| ... } ⇒ String
Render a given table and return the string representation.
74 75 76 77 78 |
# File 'lib/tty/table/renderer.rb', line 74 def 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
96 97 98 99 100 |
# File 'lib/tty/table/renderer.rb', line 96 def 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 type are
[:basic, :ascii, :unicode]
33 34 35 |
# File 'lib/tty/table/renderer.rb', line 33 def select(type) RENDERER_MAPPER[type || :basic] end |