class Text::Reform::BreakWith
Public Class Methods
new(hyphen)
click to toggle source
# File lib/text/reform.rb, line 1443 def initialize hyphen @hyphen = hyphen @hylen = hyphen.length end
Public Instance Methods
break(str, initial_max_length, total_width)
click to toggle source
Break by inserting a hyphen string.
initial_max_length
-
The maximum size of the first part of the word that will remain on the first line.
total_width
-
The total width that can be appended to this first line.
# File lib/text/reform.rb, line 1454 def break(str, initial_max_length, total_width) if total_width <= @hylen ret = [str[0...1], str[1..-1]] else ret = [str[0...(initial_max_length-@hylen)], str[(initial_max_length-@hylen)..-1]] end if ret.first =~ /\A\s*\Z/ return ['', str] else return [ret.first + @hyphen, ret.last] end end