lib/tty/table/operation/truncation.rb in tty-0.0.9 vs lib/tty/table/operation/truncation.rb in tty-0.0.10
- old
+ new
@@ -5,24 +5,35 @@
module Operation
# A class responsible for shortening text.
class Truncation
- # Apply truncation to a row
+ attr_reader :widths
+
+ # Initialize a Truncation
#
- # @param [Array] row
- # the table row
+ # @api public
+ def initialize(widths)
+ @widths = widths
+ end
+
+ # Apply truncation to a field
#
- # @return [Array[String]]
+ # @param [TTY::Table::Field] field
+ # the table field
#
+ # @param [Integer] row
+ # the field row index
+ #
+ # @param [Integer] col
+ # the field column index
+ #
+ # @return [TTY::Table::Field]
+ #
# @api public
- def call(row, options={})
- index = 0
- row.map! do |field|
- width = options.fetch(:column_widths, {})[index] || field.width
- index += 1
- field.value = truncate(field.value, width)
- end
+ def call(field, row, col)
+ width = widths[col] || field.width
+ field.value = truncate(field.value, width)
end
# Shorten given string with traling character.
#
# @param [String] string