Class: Eskimo::ASCII::TruncateRear

Inherits:
Truncate show all
Defined in:
lib/eskimo/ascii/components/truncate_rear.rb

Overview

Truncate text from the rear if it exceeds a certain width.

TruncateRear.new(width: 3) do
  "foo bar"
end
# => "foo..."

Instance Attribute Summary

Attributes inherited from Truncate

#maxlen

Instance Method Summary collapse

Methods inherited from Truncate

#initialize

Methods inherited from Component

#initialize

Constructor Details

This class inherits a constructor from Eskimo::ASCII::Truncate

Instance Method Details

#render(render:) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/eskimo/ascii/components/truncate_rear.rb', line 13

def render(render:, **)
  text = render[@children]

  if text.length >= maxlen
    text[0..maxlen - 1] + '...'
  else
    text
  end
end