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
-
#padding ⇒ Object
readonly
Returns the value of attribute padding.
-
#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, padding) ⇒ Wrapped
constructor
Initialize a Wrapped.
-
#wrap(string, width) ⇒ String
Wrap a long string according to the width.
Constructor Details
#initialize(widths, padding) ⇒ Wrapped
Initialize a Wrapped
17 18 19 20 |
# File 'lib/tty/table/operation/wrapped.rb', line 17 def initialize(widths, padding) @widths = widths @padding = padding.padding end |
Instance Attribute Details
#padding ⇒ Object (readonly)
Returns the value of attribute padding.
12 13 14 |
# File 'lib/tty/table/operation/wrapped.rb', line 12 def padding @padding end |
#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
36 37 38 39 |
# File 'lib/tty/table/operation/wrapped.rb', line 36 def call(field, row, col) width = widths[col] || field.width field.value = wrap(field.value, width) end |