Class: ReeText::WordWrap
- Inherits:
-
Object
- Object
- ReeText::WordWrap
- Includes:
- Ree::FnDSL
- Defined in:
- lib/ree_lib/packages/ree_text/package/ree_text/functions/word_wrap.rb
Constant Summary collapse
- DEFAULTS =
{ line_width: 80, break_sequence: "\n" }
Instance Method Summary collapse
Instance Method Details
#call(text, **opts) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ree_lib/packages/ree_text/package/ree_text/functions/word_wrap.rb', line 43 def call(text, **opts) = DEFAULTS.merge(opts) formated_text = text.dup formated_text.split("\n").collect do |line| if line.length > [:line_width] line .gsub(/(.{1,#{[:line_width]}})(\s+|$)/, "\\1#{[:break_sequence]}") .rstrip else line end end * [:break_sequence] end |