Sha256: d75ebd2f55f631f9f1d611b5826cd6a1b404a9c68096ed1847b08ec5261a0f36

Contents?: true

Size: 440 Bytes

Versions: 4

Compression:

Stored size: 440 Bytes

Contents

# frozen_string_literal: true

module Motoko
  module Formatters
    class Ellipsis < BaseFormatter
      attr_accessor :max_length

      def initialize(options = {})
        super
        @max_length = options.delete('max_length') || 20
      end

      def format(value)
        return nil unless value

        res = value.dup
        res[(max_length - 1)..-1] = '…' if res.length > max_length
        res
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
motoko-1.2.1 lib/motoko/formatters/ellipsis.rb
motoko-1.2.0 lib/motoko/formatters/ellipsis.rb
motoko-1.1.0 lib/motoko/formatters/ellipsis.rb
motoko-1.0.0 lib/motoko/formatters/ellipsis.rb