Method: Doing::StringTruncate#truncmiddle
- Defined in:
- lib/doing/string/truncate.rb
#truncmiddle(len, ellipsis: '...') ⇒ Object
Truncate string in the middle, separating at nearest word
62 63 64 65 66 67 68 69 |
# File 'lib/doing/string/truncate.rb', line 62 def truncmiddle(len, ellipsis: '...') return self if length <= len len -= (ellipsis.length / 2).to_i half = (len / 2).to_i start = trunc(half, ellipsis: ellipsis) finish = truncend(half, ellipsis: '') start + finish end |