Class: TTY::Table::Operation::Truncation Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/table/operation/truncation.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 responsible for shortening text.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(widths) ⇒ Truncation

Initialize a Truncation



18
19
20
# File 'lib/tty/table/operation/truncation.rb', line 18

def initialize(widths)
  @widths = widths
end

Instance Attribute Details

#widthsObject (readonly)

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.



13
14
15
# File 'lib/tty/table/operation/truncation.rb', line 13

def widths
  @widths
end

Instance Method Details

#call(field, row, col) ⇒ TTY::Table::Field

Apply truncation to a field

Parameters:

  • field (TTY::Table::Field)

    the table field

  • row (Integer)

    the field row index

  • col (Integer)

    the field column index

Returns:



36
37
38
39
# 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