Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/trellohub/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#constantizeObject



14
15
16
# File 'lib/trellohub/core_ext/string.rb', line 14

def constantize
  Object.const_get(self)
end

#ljust_with_multibyte(length, padstr = ' ') ⇒ Object Also known as: ljust



18
19
20
# File 'lib/trellohub/core_ext/string.rb', line 18

def ljust_with_multibyte(length, padstr = ' ')
  length > self.width ? "#{self}#{padstr * (length - self.width)}" : self
end

#no_coloringObject



10
11
12
# File 'lib/trellohub/core_ext/string.rb', line 10

def no_coloring
  self.gsub(/\e\[\d?\d?;?\d\d?m/, '').gsub(/\e\[0m/, '')
end

#widthObject



4
5
6
7
8
# File 'lib/trellohub/core_ext/string.rb', line 4

def width
  self.no_coloring.each_char.map { |one_letter|
    one_letter.ascii_only? ? 1 : 2
  }.inject(:+) || 0
end