Module: Cl::Wrap

Included in:
Cl, Help::Table
Defined in:
lib/cl/helper.rb

Instance Method Summary collapse

Instance Method Details

#wrap(str, opts = {}) ⇒ Object



22
23
24
25
26
27
# File 'lib/cl/helper.rb', line 22

def wrap(str, opts = {})
  width = opts[:width] || 80
  str.lines.map do |line|
    line.size > width ? line.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip : line
  end.join("\n")
end