class TTY::Table::Operation::Alignment
A class which responsiblity is to align table rows and header.
Constants
- DEFAULT
Attributes
alignments[R]
widths[R]
Public Class Methods
new(alignments, widths = nil)
click to toggle source
Initialize an Alignment
operation
@api private
# File lib/tty/table/operation/alignment.rb, line 15 def initialize(alignments, widths = nil) @alignments = alignments @widths = widths end
Public Instance Methods
call(field, row, col)
click to toggle source
Evaluate alignment of the provided row
@param [TTY::Table::Field] field
the table field
@param [Array] row
the table row
@param [Integer] col
the table column index
@return [TTY::Table::Field]
@api public
# File lib/tty/table/operation/alignment.rb, line 34 def call(field, row, col) align_field(field, col) end
Protected Instance Methods
align_field(field, col)
click to toggle source
Align each field in a row
@param [TTY::Table::Field] field
the table field
@param [Integer] col
the table column index
@return [TTY::Table::Field]
@api private
# File lib/tty/table/operation/alignment.rb, line 55 def align_field(field, col) column_width = widths[col] direction = field.alignment || alignments[col] || DEFAULT Strings.align(field.content, column_width, direction: direction) end