Module: WrappityWrap
- Defined in:
- lib/wrappity_wrap.rb,
lib/wrappity_wrap/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Method Summary collapse
Instance Method Details
#wrap(string, column) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/wrappity_wrap.rb', line 6 def wrap(string, column) return "" if string.nil? return string if string.length <= column if string[0... column].index(" ") != nil white_space = string[0... column].rindex(" ") string[0... white_space] + "\n" + wrap(string[white_space+1.. -1], column) elsif string[column] == " " string[0... column] + "\n" + wrap(string[column.. -1].strip, column) else string[0... column].strip + "\n" + wrap(string[column.. -1], column) end end |