Class: TTY::Table::Border

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

ASCII, Null, Unicode

Defined Under Namespace

Classes: ASCII, Null, Unicode

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

.charactersObject

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

Parameters:

  • type (String)

    the character type

Returns:

  • (String)


58
59
60
# File 'lib/tty/table/border.rb', line 58

def [](type)
  self.class.characters.call[type] || ''
end

#bottom_lineString

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.

Returns:

  • (String)


95
96
97
# File 'lib/tty/table/border.rb', line 95

def bottom_line
  (result = render(:bottom)).empty? ? nil : result
end

#row_lineString

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.

Returns:

  • (String)


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

#separatorString

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.

Returns:

  • (String)


76
77
78
# File 'lib/tty/table/border.rb', line 76

def separator
  (result = render(:mid)).empty? ? nil : result
end

#top_lineString

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.

Returns:

  • (String)


67
68
69
# File 'lib/tty/table/border.rb', line 67

def top_line
  (result = render(:top)).empty? ? nil : result
end