Class: TTY::Table::BorderOptions Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/table/border_options.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A class that represents table border options

Used internally by Border to manage options such as style

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(characters: {}, separator: nil, style: nil) ⇒ BorderOptions

Initialize a BorderOptions

Parameters:

  • style (String) (defaults to: nil)

    the style like :red

  • separator (String) (defaults to: nil)

    the separator character

  • characters (Hash) (defaults to: {})

    the border characters



42
43
44
45
46
# File 'lib/tty/table/border_options.rb', line 42

def initialize(characters: {}, separator: nil, style: nil)
  @characters = characters
  @separator = separator
  @style = style
end

Instance 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.



26
27
28
# File 'lib/tty/table/border_options.rb', line 26

def characters
  @characters
end

#separatorObject

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.



28
29
30
# File 'lib/tty/table/border_options.rb', line 28

def separator
  @separator
end

#styleObject

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.



30
31
32
# File 'lib/tty/table/border_options.rb', line 30

def style
  @style
end

Class Method Details

.from(options) ⇒ Object

Create options instance from hash



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tty/table/border_options.rb', line 14

def self.from(options)
  return new if options.nil?

  opts = case options
         when self.class
           options.to_hash
         else
           options
         end
  new(**opts)
end

Instance Method Details

#separator?(line) ⇒ Boolean

Check if there should be a separator AFTER this line

Parameters:

  • line (Integer)

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/tty/table/border_options.rb', line 64

def separator?(line)
  case separator
  when TTY::Table::Border::EACH_ROW
    true
  when Array
    separator.include?(line)
  when Proc
    separator.call(line)
  else
    false
  end
end

#to_hashHash

Convert to hash

Returns:

  • (Hash)


53
54
55
# File 'lib/tty/table/border_options.rb', line 53

def to_hash
  { characters: characters, separator: separator, style: style }
end