class SiSU_TextUtils::Wrap
Public Class Methods
new(para='',n_char_max=76,n_indent=0,n_hang=nil,post='')
click to toggle source
# File lib/sisu/txt_shared.rb, line 58 def initialize(para='',n_char_max=76,n_indent=0,n_hang=nil,post='') @para,@n_char_max,@n_indent,@post,=para,n_char_max,n_indent,post @n_char_max_extend = n_char_max @n_hang=n_hang ? n_hang : @n_indent end
Public Instance Methods
array_wrap()
click to toggle source
# File lib/sisu/txt_shared.rb, line 119 def array_wrap if @para.is_a?(Array) @arr=[] @para.each do |line| @arr << SiSU_TextUtils::Wrap.new(line,@n_char_max,@n_indent,@n_hang).line_wrap end end @arr end
break_line()
click to toggle source
# File lib/sisu/txt_shared.rb, line 63 def break_line "\n" end
line_wrap()
click to toggle source
# File lib/sisu/txt_shared.rb, line 66 def line_wrap space=' ' spaces_indent,spaces_hang="#{break_line}#{space*@n_indent}",space*@n_hang line=0 out=[] out[line]='' @para=@para.gsub(/<br>/,' \\ '). gsub(/#{Mx[:br_nl]}/,"\n\n") words=@para.scan(/\n\n|\s+\\\s+|<br>|\S+/m) while words != '' word=words.shift if not word out[line] unless out[line].empty? #check break elsif word =~/<br>/ word=nil out[line]=out[line].gsub(/<br>/,'') line=line elsif word =~/\n\n/ word="\n" @n_char_max_extend = @n_char_max line += 1 elsif (out[line].length + word.length) > (@n_char_max_extend - @n_indent) \ and out[line] =~/\S+/ @n_char_max_extend = @n_char_max out[line].squeeze!(' ') line += 1 end if word out[line]=if out[line] \ and out[line] !~/\S+$/m "#{out[line]}#{word}" elsif out[line] \ and out[line] =~/\S+/ "#{out[line]} #{word}" else "#{word.strip}" end end @oldword=word if word =~/\S+/ end post=(@post.empty?) \ ? '' : "\n" + (' '*@n_indent) +@post spaces_hang + out.join(spaces_indent) + post end
line_wrap_endnote()
click to toggle source
# File lib/sisu/txt_shared.rb, line 115 def line_wrap_endnote @n_indent,@n_hang=4,2 line_wrap end
line_wrap_indent1()
click to toggle source
# File lib/sisu/txt_shared.rb, line 111 def line_wrap_indent1 @n_indent,@n_hang=2,2 line_wrap end
no_wrap()
click to toggle source
# File lib/sisu/txt_shared.rb, line 128 def no_wrap @para end
no_wrap_no_breaks()
click to toggle source
# File lib/sisu/txt_shared.rb, line 131 def no_wrap_no_breaks @para.gsub(/\n/m,' ').gsub(/\s\s+/,' ') end