Class: TTY::Table::Operation::Wrapped
- Inherits:
-
Object
- Object
- TTY::Table::Operation::Wrapped
- Includes:
- Unicode
- Defined in:
- lib/tty/table/operation/wrapped.rb
Overview
A class responsible for wrapping text.
Instance Method Summary collapse
-
#wrap(string, width) ⇒ Object
Wrap a long string according to the width.
Methods included from Unicode
#as_unicode, #clean_utf8, #utf8?
Instance Method Details
#wrap(string, width) ⇒ Object
Wrap a long string according to the width.
21 22 23 24 25 26 27 28 |
# File 'lib/tty/table/operation/wrapped.rb', line 21 def wrap(string, width) as_unicode do chars = string.chars.to_a return string if chars.length <= width idx = width return chars[0, idx].join + "\n" + wrap(chars[idx..-1].join, width) end end |