Class: Troo::Wordwrap
- Inherits:
-
Object
- Object
- Troo::Wordwrap
- Defined in:
- lib/troo/presentation/formatter.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.
127 128 129 |
# File 'lib/troo/presentation/formatter.rb', line 127 def initialize(value, = {}) @value, @options = value, end |
Class Method Details
.this(value, options = {}) ⇒ Object
122 123 124 |
# File 'lib/troo/presentation/formatter.rb', line 122 def this(value, = {}) new(value, ).reformat end |
Instance Method Details
#reformat ⇒ Object
131 132 133 134 |
# File 'lib/troo/presentation/formatter.rb', line 131 def reformat return pruned if prune? wordwrapped end |
#wordwrapped ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/troo/presentation/formatter.rb', line 136 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 |