Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/git_trend/ext/string.rb
Instance Method Summary collapse
Instance Method Details
#mb_ljust(width, padding = ' ') ⇒ Object
24 25 26 27 |
# File 'lib/git_trend/ext/string.rb', line 24 def mb_ljust(width, padding = ' ') padding_size = [0, width - mb_width].max self + padding * padding_size end |
#mb_slice(width) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/git_trend/ext/string.rb', line 6 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.ascii_only? ? 1 : 2 if extraction_size + char_size > max_size extraction << '...' break end extraction_size += char_size extraction << c end extraction end |
#mb_width ⇒ Object
2 3 4 |
# File 'lib/git_trend/ext/string.rb', line 2 def mb_width each_char.inject(0) { |sum, c| sum += c.ascii_only? ? 1 : 2 } end |