Module: Sycstring
- Defined in:
- lib/sycstring/string_util.rb
Overview
Sycstring provides functions for string operations
Instance Method Summary collapse
-
#split_lines(string, length) ⇒ Object
Splits a string to size (chars) less or equal to length.
Instance Method Details
#split_lines(string, length) ⇒ Object
Splits a string to size (chars) less or equal to length
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sycstring/string_util.rb', line 5 def split_lines(string, length) lines = string.squeeze(" ").split("\n") i = 0 new_lines = [] new_lines[i] = "" lines.each do |line| line.squeeze(" ").split.each do |w| if new_lines[i].length + w.length < length new_lines[i] += "#{w} " else i += 1 new_lines[i] = "#{w} " end end i += 1 new_lines[i] = "" end text = "" new_lines.each {|l| text << "#{l}\n"} text.chomp end |