Class: Helium::Console::Formatters::MaxLines
- Inherits:
-
Object
- Object
- Helium::Console::Formatters::MaxLines
- Defined in:
- lib/helium/console/formatters/max_lines.rb
Constant Summary collapse
- ELLIPSES =
'..."'
Instance Method Summary collapse
- #call(string) ⇒ Object
-
#initialize(max_lines:, max_width:, ellipses:) ⇒ MaxLines
constructor
A new instance of MaxLines.
Constructor Details
#initialize(max_lines:, max_width:, ellipses:) ⇒ MaxLines
Returns a new instance of MaxLines.
9 10 11 12 13 |
# File 'lib/helium/console/formatters/max_lines.rb', line 9 def initialize(max_lines:, max_width:, ellipses:) @max_lines = max_lines @max_width = max_width @ellipses = ellipses end |
Instance Method Details
#call(string) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/helium/console/formatters/max_lines.rb', line 15 def call(string) return string if !@max_lines || string.lines.count <= @max_lines lines = string.lines.first(@max_lines) last_line = lines.pop lines << last_line.chars.first(@max_width - @ellipses.length).join + @ellipses lines.join end |