Class: TTY::Table::Operation::Wrapped
- Inherits:
-
Object
- Object
- TTY::Table::Operation::Wrapped
- Defined in:
- lib/tty/table/operation/wrapped.rb
Overview
A class responsible for wrapping text.
Instance Attribute Summary collapse
-
#widths ⇒ Object
readonly
Returns the value of attribute widths.
Instance Method Summary collapse
-
#call(field, row, col) ⇒ Array[String]
Apply wrapping to a field.
-
#initialize(widths) ⇒ Wrapped
constructor
Initialize a Wrapped.
-
#wrap(string, width) ⇒ String
Wrap a long string according to the width.
Constructor Details
#initialize(widths) ⇒ Wrapped
Initialize a Wrapped
15 16 17 |
# File 'lib/tty/table/operation/wrapped.rb', line 15 def initialize(widths) @widths = widths end |
Instance Attribute Details
#widths ⇒ Object (readonly)
Returns the value of attribute widths.
10 11 12 |
# File 'lib/tty/table/operation/wrapped.rb', line 10 def widths @widths end |
Instance Method Details
#call(field, row, col) ⇒ Array[String]
Apply wrapping to a field
33 34 35 36 |
# File 'lib/tty/table/operation/wrapped.rb', line 33 def call(field, row, col) width = widths[col] || field.width field.value = wrap(field.value, width) end |