Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/command-set/command-set.rb

Overview

:stopdoc:

Instance Method Summary collapse

Instance Method Details

#wrap(width = 80) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/command-set/command-set.rb', line 14

def wrap(width=80)
  scanner = StringScanner.new(self)
  result=[]

  scanner.skip(/\s*/)

  current_line = scanner.scan(/\S+/)

  until scanner.eos?
    scanner.skip(/\s*/)
    word = scanner.scan(/\S+/)
    next if word.nil?
    if word.length > (width - current_line.length) 
	result << current_line
	current_line = word
    else
	current_line << (" " + word)
    end
  end

  unless /^\s*$/ =~ current_line
    result << current_line
  end

  return result
end