Class: Vedeu::Wordwrap
- Inherits:
-
Object
- Object
- Vedeu::Wordwrap
- Defined in:
- lib/vedeu/support/wordwrap.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value, options = {}) ⇒ Wordwrap
constructor
A new instance of Wordwrap.
- #reformat ⇒ Object
- #wordwrapped ⇒ Object
Constructor Details
#initialize(value, options = {}) ⇒ Wordwrap
Returns a new instance of Wordwrap.
7 8 9 10 |
# File 'lib/vedeu/support/wordwrap.rb', line 7 def initialize(value, = {}) @value = value @options = || {} end |
Class Method Details
.this(value, options = {}) ⇒ Object
3 4 5 |
# File 'lib/vedeu/support/wordwrap.rb', line 3 def self.this(value, = {}) new(value, ).reformat end |
Instance Method Details
#reformat ⇒ Object
12 13 14 15 16 |
# File 'lib/vedeu/support/wordwrap.rb', line 12 def reformat return pruned if prune? wordwrapped end |
#wordwrapped ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vedeu/support/wordwrap.rb', line 18 def wordwrapped processed = [] value.split(/\n/).map do |unprocessed| line_length = 0 reformatted = [] unprocessed.split(/\s/).map do |word| word_length = word.length + 1 if (line_length += word_length) >= maximum_width line_length = word_length processed << reformatted reformatted = [] end reformatted << word end processed << reformatted end output(processed) end |