Method: #wordwrap

Defined in:
lib/cli/database_console_init.rb

#wordwrap(string, max = 80, indent = "") ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cli/database_console_init.rb', line 10

def wordwrap(string, max = 80, indent = "")
  strings = [""]
  string.split(", ").each do |item|
    if strings.last.length == 0 || strings.last.length + item.length <= max
      strings.last << item << ', '
    else
      strings << (item + ', ')
    end
  end
  strings.map(&:strip).join("\n#{indent}").slice(0..-2)
end