Class: TTY::Table::Operation::Wrapped Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/table/operation/wrapped.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 wrapping text.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(widths) ⇒ Wrapped

Initialize a Wrapped



17
18
19
# File 'lib/tty/table/operation/wrapped.rb', line 17

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.



12
13
14
# File 'lib/tty/table/operation/wrapped.rb', line 12

def widths
  @widths
end

Instance Method Details

#call(field, row, col) ⇒ Array[String]

Apply wrapping to a field

Parameters:

  • field (TTY::Table::Field)

    the table field

  • row (Integer)

    the field row index

  • col (Integer)

    the field column index

Returns:

  • (Array[String])


35
36
37
38
# File 'lib/tty/table/operation/wrapped.rb', line 35

def call(field, row, col)
  column_width = widths[col] || field.width
  Strings.wrap(field.content, column_width)
end