class TTY::Table::Operation::Truncation
A class responsible for shortening text.
@api private
Attributes
widths[R]
Public Class Methods
new(widths)
click to toggle source
Initialize a Truncation
@api public
# File lib/tty/table/operation/truncation.rb, line 18 def initialize(widths) @widths = widths end
Public Instance Methods
call(field, row, col)
click to toggle source
Apply truncation to a field
@param [TTY::Table::Field] field
the table field
@param [Integer] row
the field row index
@param [Integer] col
the field column index
@return [TTY::Table::Field]
@api public
# File lib/tty/table/operation/truncation.rb, line 36 def call(field, row, col) column_width = widths[col] || field.width Strings.truncate(field.content, column_width) end