Class: Eskimo::Components::Truncate
- Inherits:
-
Eskimo::Component
- Object
- Eskimo::Component
- Eskimo::Components::Truncate
- Defined in:
- lib/eskimo/components.rb
Overview
Truncate text from the beginning if it exceeds a certain width.
...
Direct Known Subclasses
Instance Attribute Summary collapse
-
#maxlen ⇒ Object
readonly
Returns the value of attribute maxlen.
Instance Method Summary collapse
-
#initialize(reserve: 0, width: SCREEN_COLUMNS, &children) ⇒ Truncate
constructor
A new instance of Truncate.
- #render ⇒ Object
Constructor Details
#initialize(reserve: 0, width: SCREEN_COLUMNS, &children) ⇒ Truncate
Returns a new instance of Truncate.
68 69 70 71 72 |
# File 'lib/eskimo/components.rb', line 68 def initialize(reserve: 0, width: SCREEN_COLUMNS, &children) @maxlen = [0, width - reserve].max super(&children) end |
Instance Attribute Details
#maxlen ⇒ Object (readonly)
Returns the value of attribute maxlen.
66 67 68 |
# File 'lib/eskimo/components.rb', line 66 def maxlen @maxlen end |
Instance Method Details
#render ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/eskimo/components.rb', line 74 def render(**) text = super if text.length >= maxlen '...' + text[text.length - maxlen - 1 .. -1] else text end end |