Module: Wrapword

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

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.space(word, limit) ⇒ Object



13
14
15
# File 'lib/wrapword.rb', line 13

def self.space(word,limit)
  word[0...limit].rindex(' ')
end

.wrap(word, limit) ⇒ Object



6
7
8
9
10
11
# File 'lib/wrapword.rb', line 6

def self.wrap(word, limit)
  return word if word.length <= limit
  space = limit
  space = space(word,limit) if space(word,limit) 
  "#{word[0...space]}\n#{wrap(word[space..-1].strip, limit)}"
end