Sha256: 7a0b69fb51f2bd0446fab7a6ec903db1adf3c8c83e49258403d24ab1ca5cdf4e
Contents?: true
Size: 426 Bytes
Versions: 1
Compression:
Stored size: 426 Bytes
Contents
require 'unicode/display_width' class String def mb_slice(width) return '' if empty? max_size = width - 3 # 3 is '...' size. extraction_size = 0 extraction = '' each_char do |c| char_size = c.display_width if extraction_size + char_size > max_size extraction << '...' break end extraction_size += char_size extraction << c end extraction end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
git-trend-0.1.7 | lib/git_trend/ext/string.rb |