Method: String#shorten
- Defined in:
- lib/midwire_common/string.rb
#shorten(maxcount = 30) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/midwire_common/string.rb', line 93 def shorten(maxcount = 30) if length >= maxcount shortened = self[0, maxcount] splitted = shortened.split(/\s/) if splitted.length > 1 words = splitted.length splitted[0, words - 1].join(' ') + '...' else shortened[0, maxcount - 3] + '...' end else self end end |