class TTY::Table::BorderOptions

A class that represents table border options

Used internally by {Table::Border} to manage options such as style

@api private

Attributes

characters[RW]
separator[RW]
style[RW]

Public Class Methods

from(options) click to toggle source

Create options instance from hash

@api public

# 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
new(characters: {}, separator: nil, style: nil) click to toggle source

Initialize a BorderOptions

@param [String] style

the style like :red

@param [String] separator

the separator character

@param [Hash] characters

the border characters

@api public

# File lib/tty/table/border_options.rb, line 42
def initialize(characters: {}, separator: nil, style: nil)
  @characters = characters
  @separator = separator
  @style = style
end

Public Instance Methods

separator?(line) click to toggle source

Check if there should be a separator AFTER this line

@param [Integer] line

@return [Boolean]

@api public

# 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_hash() click to toggle source

Convert to hash

@return [Hash]

@api public

# File lib/tty/table/border_options.rb, line 53
def to_hash
  { characters: characters, separator: separator, style: style }
end