Class: TTY::Table::Border
- Inherits:
-
Object
- Object
- TTY::Table::Border
- Includes:
- Unicode
- Defined in:
- lib/tty/table/border.rb,
lib/tty/table/border/null.rb,
lib/tty/table/border/ascii.rb,
lib/tty/table/border/unicode.rb
Overview
Abstract base class that is responsible for building the table border.
Defined Under Namespace
Class Attribute Summary collapse
-
.characters ⇒ Object
private
Store characters for border.
Class Method Summary collapse
-
.def_border(&block) ⇒ Object
Define border characters.
Instance Method Summary collapse
-
#[](type) ⇒ String
private
Retrive individula character by type.
-
#bottom_line ⇒ String
private
A line spannig all columns marking bottom of a table.
-
#initialize(row = nil) ⇒ Object
constructor
private
Instantiate a new object.
-
#row_line ⇒ String
private
A line spanning all columns delemeting cells in a row.
-
#separator ⇒ String
private
A line spanning all columns delemeting rows in a table.
-
#top_line ⇒ String
private
A line spanning all columns marking top of a table.
Methods included from Unicode
#as_unicode, #clean_utf8, #utf8?
Constructor Details
#initialize(row = nil) ⇒ 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.
Instantiate a new object
34 35 36 37 38 39 40 41 |
# File 'lib/tty/table/border.rb', line 34 def initialize(row=nil) if self.class == Border raise NotImplementedError, "#{self} is an abstract class" else @row = row @widths = row.map { |cell| cell.chars.to_a.size } end end |
Class Attribute Details
.characters ⇒ 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.
Store characters for border
26 27 28 |
# File 'lib/tty/table/border.rb', line 26 def characters @characters end |
Class Method Details
.def_border(&block) ⇒ Object
Define border characters
46 47 48 |
# File 'lib/tty/table/border.rb', line 46 def self.def_border(&block) @characters = block end |
Instance Method Details
#[](type) ⇒ String
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.
Retrive individula character by type
58 59 60 |
# File 'lib/tty/table/border.rb', line 58 def [](type) self.class.characters.call[type] || '' end |
#bottom_line ⇒ String
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.
A line spannig all columns marking bottom of a table.
95 96 97 |
# File 'lib/tty/table/border.rb', line 95 def bottom_line (result = render(:bottom)).empty? ? nil : result end |
#row_line ⇒ String
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.
A line spanning all columns delemeting cells in a row.
85 86 87 88 |
# File 'lib/tty/table/border.rb', line 85 def row_line result = self['left'] + row.join(self['right']) + self['right'] result.empty? ? nil : result end |
#separator ⇒ String
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.
A line spanning all columns delemeting rows in a table.
76 77 78 |
# File 'lib/tty/table/border.rb', line 76 def separator (result = render(:mid)).empty? ? nil : result end |
#top_line ⇒ String
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.
A line spanning all columns marking top of a table.
67 68 69 |
# File 'lib/tty/table/border.rb', line 67 def top_line (result = render(:top)).empty? ? nil : result end |