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, padding) ⇒ Wrapped

Initialize a Wrapped



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

def initialize(widths, padding)
  @widths  = widths
  @padding = padding.padding
end

Instance Attribute Details

#paddingObject (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/wrapped.rb', line 13

def padding
  @padding
end

#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.



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

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])


37
38
39
40
# File 'lib/tty/table/operation/wrapped.rb', line 37

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

#wrap(string, width) ⇒ String

Wrap a long string according to the width.

Parameters:

  • string (String)

    the string to wrap

  • width (Integer)

    the maximum width

Returns:

  • (String)


52
53
54
# File 'lib/tty/table/operation/wrapped.rb', line 52

def wrap(string, width)
  TTY::Text.wrap(string, width, padding: padding)
end