Class: TTY::Table::Border
- Inherits:
-
Object
- Object
- TTY::Table::Border
- 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,
lib/tty/table/border/row_line.rb
Overview
Abstract base class that is responsible for building the table border.
Defined Under Namespace
Classes: ASCII, Null, RowLine, Unicode
Constant Summary collapse
- EMPTY_CHAR =
''.freeze
- SPACE_CHAR =
' '.freeze
- EACH_ROW =
Represent a separtor on each row
:each_row
Class Attribute Summary collapse
-
.characters ⇒ Object
private
Store characters for border.
Instance Attribute Summary collapse
-
#border ⇒ Object
readonly
The table custom border characters.
Attributes included from Equatable
Class Method Summary collapse
-
.def_border(characters = (not_set=true), &block) ⇒ Hash
Define border characters.
-
.set_color(color, *strings) ⇒ Array[String]
Set color on 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.
-
#color? ⇒ Boolean
Check if border color is set.
-
#initialize(column_widths, options = nil) ⇒ Object
constructor
private
Instantiate a new object.
-
#row_line(row) ⇒ String
A line spanning all columns delemeting fields 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 Equatable
#attr_reader, included, #inherited
Methods included from Unicode
#as_unicode, #clean_utf8, #utf8?
Constructor Details
#initialize(column_widths, options = 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
43 44 45 46 47 48 49 50 |
# File 'lib/tty/table/border.rb', line 43 def initialize(column_widths, = nil) if self.class == Border fail NotImplementedError, "#{self} is an abstract class" else @widths = column_widths @border = TTY::Table::BorderOptions.from 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
30 31 32 |
# File 'lib/tty/table/border.rb', line 30 def characters @characters end |
Instance Attribute Details
#border ⇒ Object (readonly)
The table custom border characters
24 25 26 |
# File 'lib/tty/table/border.rb', line 24 def border @border end |
Class Method Details
.def_border(characters = (not_set=true), &block) ⇒ Hash
Define border characters
60 61 62 63 64 65 |
# File 'lib/tty/table/border.rb', line 60 def self.def_border(characters=(not_set=true), &block) return self.characters = characters unless not_set dsl = TTY::Table::BorderDSL.new(&block) self.characters = dsl.characters end |
.set_color(color, *strings) ⇒ Array[String]
Set color on characters
99 100 101 |
# File 'lib/tty/table/border.rb', line 99 def self.set_color(color, *strings) strings.map { |string| TTY.terminal.color.set(string, color) } 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
75 76 77 78 79 |
# File 'lib/tty/table/border.rb', line 75 def [](type) characters = self.class.characters chars = border.nil? ? characters : characters.merge(border.characters) chars[type] || EMPTY_CHAR 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.
117 118 119 |
# File 'lib/tty/table/border.rb', line 117 def bottom_line (result = render(:bottom)).empty? ? nil : result end |
#color? ⇒ Boolean
Check if border color is set
86 87 88 |
# File 'lib/tty/table/border.rb', line 86 def color? border && border.style end |
#row_line(row) ⇒ String
A line spanning all columns delemeting fields in a row.
138 139 140 141 142 143 144 |
# File 'lib/tty/table/border.rb', line 138 def row_line(row) line = RowLine.new(self['left'], self['center'], self['right']) line.colorize(border.style) if color? result = row_heights(row, line) result.empty? ? EMPTY_CHAR : 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.
126 127 128 |
# File 'lib/tty/table/border.rb', line 126 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.
108 109 110 |
# File 'lib/tty/table/border.rb', line 108 def top_line (result = render(:top)).empty? ? nil : result end |