Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/utils/utils.rb,
lib/utils/utils.rb
Instance Method Summary collapse
- #bg_black ⇒ Object
- #bg_blue ⇒ Object
- #bg_brown ⇒ Object
- #bg_cyan ⇒ Object
- #bg_gray ⇒ Object
- #bg_green ⇒ Object
- #bg_magenta ⇒ Object
- #bg_red ⇒ Object
- #black ⇒ Object
- #blink ⇒ Object
- #blue ⇒ Object
- #bold ⇒ Object
- #brown ⇒ Object
- #capitalize_first ⇒ Object
- #capitalize_first! ⇒ Object
- #cyan ⇒ Object
- #delete_last_path_component ⇒ Object
- #gray ⇒ Object
- #green ⇒ Object
- #include_one_of?(*array) ⇒ Boolean
- #italic ⇒ Object
- #lowercase_first ⇒ Object
- #magenta ⇒ Object
- #path_intersection(other) ⇒ Object
- #red ⇒ Object
- #reverse_color ⇒ Object
- #underline ⇒ Object
- #underscore ⇒ Object
Instance Method Details
#bg_black ⇒ Object
89 |
# File 'lib/utils/utils.rb', line 89 def bg_black; "\e[40m#{self}\e[0m" end |
#bg_blue ⇒ Object
93 |
# File 'lib/utils/utils.rb', line 93 def bg_blue; "\e[44m#{self}\e[0m" end |
#bg_brown ⇒ Object
92 |
# File 'lib/utils/utils.rb', line 92 def bg_brown; "\e[43m#{self}\e[0m" end |
#bg_cyan ⇒ Object
95 |
# File 'lib/utils/utils.rb', line 95 def bg_cyan; "\e[46m#{self}\e[0m" end |
#bg_gray ⇒ Object
96 |
# File 'lib/utils/utils.rb', line 96 def bg_gray; "\e[47m#{self}\e[0m" end |
#bg_green ⇒ Object
91 |
# File 'lib/utils/utils.rb', line 91 def bg_green; "\e[42m#{self}\e[0m" end |
#bg_magenta ⇒ Object
94 |
# File 'lib/utils/utils.rb', line 94 def bg_magenta; "\e[45m#{self}\e[0m" end |
#bg_red ⇒ Object
90 |
# File 'lib/utils/utils.rb', line 90 def bg_red; "\e[41m#{self}\e[0m" end |
#black ⇒ Object
80 |
# File 'lib/utils/utils.rb', line 80 def black; "\e[30m#{self}\e[0m" end |
#blink ⇒ Object
101 |
# File 'lib/utils/utils.rb', line 101 def blink; "\e[5m#{self}\e[25m" end |
#blue ⇒ Object
84 |
# File 'lib/utils/utils.rb', line 84 def blue; "\e[34m#{self}\e[0m" end |
#bold ⇒ Object
98 |
# File 'lib/utils/utils.rb', line 98 def bold; "\e[1m#{self}\e[22m" end |
#brown ⇒ Object
83 |
# File 'lib/utils/utils.rb', line 83 def brown; "\e[33m#{self}\e[0m" end |
#capitalize_first ⇒ Object
18 19 20 |
# File 'lib/utils/utils.rb', line 18 def capitalize_first self.slice(0,1).capitalize + self.slice(1..-1) end |
#capitalize_first! ⇒ Object
21 22 23 |
# File 'lib/utils/utils.rb', line 21 def capitalize_first! self.replace(self.capitalize_first) end |
#cyan ⇒ Object
86 |
# File 'lib/utils/utils.rb', line 86 def cyan; "\e[36m#{self}\e[0m" end |
#delete_last_path_component ⇒ Object
54 55 56 |
# File 'lib/utils/utils.rb', line 54 def delete_last_path_component self.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR) end |
#gray ⇒ Object
87 |
# File 'lib/utils/utils.rb', line 87 def gray; "\e[37m#{self}\e[0m" end |
#green ⇒ Object
82 |
# File 'lib/utils/utils.rb', line 82 def green; "\e[32m#{self}\e[0m" end |
#include_one_of?(*array) ⇒ Boolean
12 13 14 15 16 17 |
# File 'lib/utils/utils.rb', line 12 def include_one_of?(*array) array.flatten.each do |str| return true if self.include?(str) end false end |
#italic ⇒ Object
99 |
# File 'lib/utils/utils.rb', line 99 def italic; "\e[3m#{self}\e[23m" end |
#lowercase_first ⇒ Object
24 25 26 27 |
# File 'lib/utils/utils.rb', line 24 def lowercase_first str = to_s str[0,1].downcase + str[1..-1] end |
#magenta ⇒ Object
85 |
# File 'lib/utils/utils.rb', line 85 def magenta; "\e[35m#{self}\e[0m" end |
#path_intersection(other) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/utils/utils.rb', line 35 def path_intersection(other) component_start = 0 (0..[other.size, self.size].min).each { |i| if self[i] == '/' component_start = i end if self[i] != other[i] if i > 0 return self[0..component_start] else return '' end end } self end |
#red ⇒ Object
81 |
# File 'lib/utils/utils.rb', line 81 def red; "\e[31m#{self}\e[0m" end |
#reverse_color ⇒ Object
102 |
# File 'lib/utils/utils.rb', line 102 def reverse_color; "\e[7m#{self}\e[27m" end |
#underline ⇒ Object
100 |
# File 'lib/utils/utils.rb', line 100 def underline; "\e[4m#{self}\e[24m" end |
#underscore ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/utils/utils.rb', line 28 def underscore self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |