Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/wooget/util/misc.rb
Constant Summary collapse
- REGEXP_PATTERN =
/\033\[([0-9]+);([0-9]+);([0-9]+)m(.+?)\033\[0m|([^\033]+)/m
Instance Method Summary collapse
-
#snake_case ⇒ Object
convert to snake case.
-
#uncolorize ⇒ Object
get rid of goddamn ansi control codes.
Instance Method Details
#snake_case ⇒ Object
convert to snake case
84 85 86 87 88 89 90 |
# File 'lib/wooget/util/misc.rb', line 84 def snake_case self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2'). tr("-", "_"). downcase end |
#uncolorize ⇒ Object
get rid of goddamn ansi control codes
74 75 76 77 78 79 80 81 |
# File 'lib/wooget/util/misc.rb', line 74 def uncolorize result = self.scan(REGEXP_PATTERN).inject("") do |str, match| str << (match[3] || match[4]) end #more ansi control codes that the above doesn't pickup result.gsub(/\[(?:[A-Z0-9]{1,2}[nmKM]?)|\[(?:\?.*[=<>])|(?:;\d+[nmKM]?)/, '') end |