Sha256: 71e482b4a136af26eaf9e7ab46bb9bffdb8ac20eeda8bcfe56e9cf58e709e9a4

Contents?: true

Size: 900 Bytes

Versions: 1

Compression:

Stored size: 900 Bytes

Contents

# encoding: utf-8

require 'strings'

module TTY
  class Table
    module Operation
      # A class responsible for wrapping text.
      #
      # @api private
      class Wrapped
        attr_reader :widths

        # Initialize a Wrapped
        #
        # @api public
        def initialize(widths)
          @widths  = widths
        end

        # Apply wrapping to a field
        #
        # @param [TTY::Table::Field] field
        #   the table field
        #
        # @param [Integer] row
        #   the field row index
        #
        # @param [Integer] col
        #   the field column index
        #
        # @return [Array[String]]
        #
        # @api public
        def call(field, row, col)
          column_width = widths[col] || field.width
          Strings.wrap(field.content, column_width)
        end
      end # Wrapped
    end # Operation
  end # Table
end # TTY

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tty-table-0.10.0 lib/tty/table/operation/wrapped.rb