Module: WordWrapTing

Defined in:
lib/word_wrap_ting.rb,
lib/word_wrap_ting/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.wrap(str, max_len) ⇒ Object



8
9
10
11
12
13
# File 'lib/word_wrap_ting.rb', line 8

def self.wrap(str, max_len)
  return str if str.length <= max_len

  break_col = str[0...max_len].rindex(' ') || max_len
  str[0...break_col].strip << "\n" << self.wrap(str[break_col..-1].strip, max_len)
end