Class: TTY::Table::Operation::Truncation
- Inherits:
-
Object
- Object
- TTY::Table::Operation::Truncation
- Defined in:
- lib/tty/table/operation/truncation.rb
Overview
A class responsible for shortening text.
Instance Attribute Summary collapse
-
#widths ⇒ Object
readonly
Returns the value of attribute widths.
Instance Method Summary collapse
-
#call(field, row, col) ⇒ TTY::Table::Field
Apply truncation to a field.
-
#initialize(widths) ⇒ Truncation
constructor
Initialize a Truncation.
-
#truncate(string, width) ⇒ String
Shorten given string with traling character.
Constructor Details
#initialize(widths) ⇒ Truncation
Initialize a Truncation
15 16 17 |
# File 'lib/tty/table/operation/truncation.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/truncation.rb', line 10 def widths @widths end |
Instance Method Details
#call(field, row, col) ⇒ TTY::Table::Field
Apply truncation to a field
33 34 35 36 |
# File 'lib/tty/table/operation/truncation.rb', line 33 def call(field, row, col) width = widths[col] || field.width field.value = truncate(field.value, width) end |