Class: Motoko::Formatters::Ellipsis
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- Motoko::Formatters::Ellipsis
- Defined in:
- lib/motoko/formatters/ellipsis.rb
Instance Attribute Summary collapse
-
#max_length ⇒ Object
Returns the value of attribute max_length.
Instance Method Summary collapse
- #format(value) ⇒ Object
-
#initialize(options = {}) ⇒ Ellipsis
constructor
A new instance of Ellipsis.
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( = {}) super @max_length = .delete('max_length') || 20 end |
Instance Attribute Details
#max_length ⇒ Object
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 |