class TTY::Table::AlignmentSet

A class responsible for column alignments

Used internally by {TTY::Table::Operation::Alignment}

Constants

DEFAULT

Attributes

alignments[R]

Public Class Methods

new(alignments) click to toggle source

Initialize an AlignmentSet

@param [AlignmentSet, Array] alignments

the alignments for the renderer

@api private

# File lib/tty/table/alignment_set.rb, line 19
def initialize(alignments)
  @alignments = Array(alignments).map(&:to_sym)
end

Public Instance Methods

[](index) click to toggle source

Lookup an alignment by index

@param [Integer] index

@return [Symbol] alignment

@api public

# File lib/tty/table/alignment_set.rb, line 45
def [](index)
  alignments.fetch(index, DEFAULT)
end
each() { |element| ... } click to toggle source

Iterate over each element in the alignment set

@example

alignment = AlignmentSet.new [1,2,3]
alignment.each { |element| ... }

@return [self]

@api public

# File lib/tty/table/alignment_set.rb, line 32
def each
  return to_enum unless block_given?
  to_ary.each { |element| yield element }
  self
end
to_ary() click to toggle source

Convert to array

@return [Array]

@api public

# File lib/tty/table/alignment_set.rb, line 54
def to_ary
  alignments.to_a
end
to_s() click to toggle source

String representation of aligments

@return [String]

@api public

# File lib/tty/table/alignment_set.rb, line 63
def to_s
  to_ary
end