Method: Wlog::Helpers.break_string

Defined in:
lib/wlog/domain/helpers.rb

.break_string(string, numchars) ⇒ Object

Break the string to a different line

Parameters:

  • string

    is the string that we want processed.

  • numchars

    is the amount of characters max per line.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wlog/domain/helpers.rb', line 12

def self.break_string(string,numchars)
  return unless string
  desc , cl = "", 0
  string.split.each do |word|
    wlength = word.length
    if cl + wlength + 1 > numchars
      cl = 0
      desc.concat($/)
    end
    desc.concat(word).concat(" ")
    cl += wlength + 1
  end
  desc.chomp!
desc end