class Shellout::Paragraph
Public Class Methods
new(str)
click to toggle source
# File lib/shellout/paragraph.rb, line 4 def initialize(str) @str = str @padding = 0 @width = 80 end
Public Instance Methods
padding(width)
click to toggle source
# File lib/shellout/paragraph.rb, line 15 def padding(width) @padding = width self end
print(out=$stdout)
click to toggle source
# File lib/shellout/paragraph.rb, line 20 def print(out=$stdout) text_width = @width - @padding text = ' '*@padding + @str # Stolen from ActionView::Helpers::TextHelper#word_wrap p = text.split("\n").collect do |line| line.length > text_width ? line.gsub(/(.{1,#{text_width}})(\s+|$)/, "\\1\n" + ' '*@padding).rstrip : line end * "\n" out.puts p end
width(width)
click to toggle source
# File lib/shellout/paragraph.rb, line 10 def width(width) @width = width self end