Class: TTY::Text::Wrapping
- Inherits:
-
Object
- Object
- TTY::Text::Wrapping
- Includes:
- Unicode
- Defined in:
- lib/tty/text/wrapping.rb
Overview
A class responsible for text wrapping operations
Instance Attribute Summary collapse
-
#indent ⇒ Object
readonly
Returns the value of attribute indent.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text, *args) ⇒ Wrapping
constructor
private
Initialize a Wrapping.
-
#wrap ⇒ Object
private
Wrap a text into lines no longer than length.
Methods included from Unicode
#as_unicode, #clean_utf8, #utf8?
Constructor Details
#new(text, value) ⇒ Wrapping #new(text, value, options) ⇒ Wrapping
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a Wrapping
33 34 35 36 37 38 39 |
# File 'lib/tty/text/wrapping.rb', line 33 def initialize(text, *args) = Utils.(args) @text = text @length = .fetch(:length) { DEFAULT_WIDTH } @indent = .fetch(:indent) { 0 } @length = args[0] unless args.empty? end |
Instance Attribute Details
#indent ⇒ Object (readonly)
Returns the value of attribute indent.
14 15 16 |
# File 'lib/tty/text/wrapping.rb', line 14 def indent @indent end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
12 13 14 |
# File 'lib/tty/text/wrapping.rb', line 12 def length @length end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
10 11 12 |
# File 'lib/tty/text/wrapping.rb', line 10 def text @text end |
Instance Method Details
#wrap ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Wrap a text into lines no longer than length
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/tty/text/wrapping.rb', line 46 def wrap return text unless length && length > 0 as_unicode do text.split(NEWLINE).map do |line| modified_line = wrap_line line indent_line modified_line end * NEWLINE end end |