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 =
""
- SPACE_CHAR =
" "
- EACH_ROW =
Represent a separtor on each row
:each_row
- SEPARATOR =
specify a separator as a row
:separator
Class Attribute Summary collapse
-
.characters ⇒ Object
private
Store characters for border.
Class Method Summary collapse
-
.def_border(characters = (not_set = true), &block) ⇒ Hash
Define border characters.
Instance Method Summary collapse
-
#[](type) ⇒ String
private
Retrive individual 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, border_opts = nil) ⇒ Object
constructor
private
Instantiate a new object.
-
#middle_line ⇒ String
private
A line spanning all columns delemeting rows in a table.
-
#row_line(row) ⇒ String
A line spanning all columns delemeting fields in a row.
-
#set_color(color, string) ⇒ String
Set color for a string.
-
#top_line ⇒ String
private
A line spanning all columns marking top of a table.
Constructor Details
#initialize(column_widths, border_opts = 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
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tty/table/border.rb', line 56 def initialize(column_widths, border_opts = nil) if self.class == Border raise NotImplementedError, "#{self} is an abstract class" end @widths = column_widths @dsl = BorderDSL.new(border_opts) @characters = self.class.characters.merge(@dsl.characters) @color = Pastel.new 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
28 29 30 |
# File 'lib/tty/table/border.rb', line 28 def characters @characters end |
Class Method Details
.def_border(characters = (not_set = true), &block) ⇒ Hash
Define border characters
39 40 41 42 43 44 |
# File 'lib/tty/table/border.rb', line 39 def self.def_border(characters = (not_set = true), &block) return self.characters = characters unless not_set dsl = BorderDSL.new(&block) self.characters = dsl.characters 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 individual character by type
75 76 77 |
# File 'lib/tty/table/border.rb', line 75 def [](type) @characters[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.
102 103 104 |
# File 'lib/tty/table/border.rb', line 102 def bottom_line (result = render(:bottom)).empty? ? nil : result end |
#color? ⇒ Boolean
Check if border color is set
84 85 86 |
# File 'lib/tty/table/border.rb', line 84 def color? !!@dsl.style end |
#middle_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 rows in a table.
111 112 113 |
# File 'lib/tty/table/border.rb', line 111 def middle_line (result = render(:mid)).empty? ? nil : result end |
#row_line(row) ⇒ String
A line spanning all columns delemeting fields in a row.
123 124 125 126 127 128 129 |
# File 'lib/tty/table/border.rb', line 123 def row_line(row) line = RowLine.new(self["left"], self["center"], self["right"]) line.colorize(self, @dsl.style) if color? result = row_heights(row, line) result.empty? ? EMPTY_CHAR : result end |
#set_color(color, string) ⇒ String
Set color for a string
141 142 143 144 145 |
# File 'lib/tty/table/border.rb', line 141 def set_color(color, string) return string if string.gsub(/\s+/, EMPTY_CHAR).empty? @color.decorate(string, color) 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.
93 94 95 |
# File 'lib/tty/table/border.rb', line 93 def top_line (result = render(:top)).empty? ? nil : result end |