module WordWrapLimiter
Constants
- VERSION
Public Class Methods
wrap(string, column_length)
click to toggle source
# File lib/word_wrap_limiter.rb, line 4 def self.wrap(string, column_length) return string if string.length <= column_length break_point = string[0...column_length].rindex(' ') || column_length if has_space?(string, column_length) string[0...break_point] + "\n" + wrap(string[break_point + 1..-1], column_length) else string[0...break_point] + "\n" + wrap(string[break_point..-1], column_length) end end
Private Class Methods
has_space?(string, column_length)
click to toggle source
# File lib/word_wrap_limiter.rb, line 16 def self.has_space?(string, column_length) string[0...column_length].index(' ') != nil || string[column_length] == " " end