| Module | Gem::Text |
| In: |
lib/rubygems/text.rb
|
A collection of text-wrangling methods
Wraps text to wrap characters and optionally indents by indent characters
# File lib/rubygems/text.rb, line 12
12: def format_text(text, wrap, indent=0)
13: result = []
14: work = text.dup
15:
16: while work.length > wrap do
17: if work =~ /^(.{0,#{wrap}})[ \n]/ then
18: result << $1
19: work.slice!(0, $&.length)
20: else
21: result << work.slice!(0, wrap)
22: end
23: end
24:
25: result << work if work.length.nonzero?
26: result.join("\n").gsub(/^/, " " * indent)
27: end