Class: Shellout::Paragraph
- Inherits:
-
Object
- Object
- Shellout::Paragraph
- Defined in:
- lib/shellout/paragraph.rb
Instance Method Summary collapse
-
#initialize(str) ⇒ Paragraph
constructor
A new instance of Paragraph.
- #padding(width) ⇒ Object
- #print(out = $stdout) ⇒ Object
- #width(width) ⇒ Object
Constructor Details
#initialize(str) ⇒ Paragraph
Returns a new instance of Paragraph.
4 5 6 7 8 |
# File 'lib/shellout/paragraph.rb', line 4 def initialize(str) @str = str @padding = 0 @width = 80 end |
Instance Method Details
#padding(width) ⇒ Object
15 16 17 18 |
# File 'lib/shellout/paragraph.rb', line 15 def padding(width) @padding = width self end |
#print(out = $stdout) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# 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) ⇒ Object
10 11 12 13 |
# File 'lib/shellout/paragraph.rb', line 10 def width(width) @width = width self end |