Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/localio/string_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #camel_case ⇒ Object
- #cyan ⇒ Object
- #green ⇒ Object
- #red ⇒ Object
- #replace_escaped ⇒ Object
- #space_to_underscore ⇒ Object
- #strip_tag ⇒ Object
- #uncapitalize ⇒ Object
- #underscore ⇒ Object
- #yellow ⇒ Object
Class Method Details
.colorize(text, color_code) ⇒ Object
2 3 4 |
# File 'lib/localio/string_helper.rb', line 2 def self.colorize(text, color_code) "\e[#{color_code}m#{text}\e[0m" end |
Instance Method Details
#blank? ⇒ Boolean
51 52 53 |
# File 'lib/localio/string_helper.rb', line 51 def blank? respond_to?(:empty?) ? empty? : !self end |
#camel_case ⇒ Object
42 43 44 45 |
# File 'lib/localio/string_helper.rb', line 42 def camel_case return self if self !~ /_/ && self =~ /[A-Z]+.*/ split('_').map{|e| e.capitalize}.join end |
#cyan ⇒ Object
6 7 8 |
# File 'lib/localio/string_helper.rb', line 6 def cyan self.class.colorize(self, 36) end |
#green ⇒ Object
10 11 12 |
# File 'lib/localio/string_helper.rb', line 10 def green self.class.colorize(self, 32) end |
#red ⇒ Object
18 19 20 |
# File 'lib/localio/string_helper.rb', line 18 def red self.class.colorize(self, 31) end |
#replace_escaped ⇒ Object
38 39 40 |
# File 'lib/localio/string_helper.rb', line 38 def replace_escaped self.gsub("`+", "+").gsub("`=","=").gsub("\\+", "+").gsub("\\=","=") end |
#space_to_underscore ⇒ Object
34 35 36 |
# File 'lib/localio/string_helper.rb', line 34 def space_to_underscore self.gsub(' ', '_') end |
#strip_tag ⇒ Object
30 31 32 |
# File 'lib/localio/string_helper.rb', line 30 def strip_tag self.gsub(/^[\[][a-z][\]]/, '') end |
#uncapitalize ⇒ Object
47 48 49 |
# File 'lib/localio/string_helper.rb', line 47 def uncapitalize self[0, 1].downcase + self[1..-1] end |
#underscore ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/localio/string_helper.rb', line 22 def underscore self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2'). tr("-", "_"). downcase end |
#yellow ⇒ Object
14 15 16 |
# File 'lib/localio/string_helper.rb', line 14 def yellow self.class.colorize(self, 33) end |