Class: Motoko::Formatters::Ellipsis

Inherits:
BaseFormatter show all
Defined in:
lib/motoko/formatters/ellipsis.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Ellipsis

Returns a new instance of Ellipsis.



8
9
10
11
# File 'lib/motoko/formatters/ellipsis.rb', line 8

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

Instance Attribute Details

#max_lengthObject

Returns the value of attribute max_length.



6
7
8
# File 'lib/motoko/formatters/ellipsis.rb', line 6

def max_length
  @max_length
end

Instance Method Details

#format(value) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/motoko/formatters/ellipsis.rb', line 13

def format(value)
  return nil unless value

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