Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/site_hook/string_ext.rb
Instance Method Summary collapse
- #camelcase ⇒ Object
- #camelcase! ⇒ Object
- #camelize ⇒ Object
- #camelize! ⇒ Object
- #safe_log_name ⇒ Object
- #squish ⇒ Object
- #squish! ⇒ Object
- #underscore ⇒ Object
- #underscore! ⇒ Object
Instance Method Details
#camelcase ⇒ Object
25 26 27 |
# File 'lib/site_hook/string_ext.rb', line 25 def camelcase dup.camelcase! end |
#camelcase! ⇒ Object
22 23 24 |
# File 'lib/site_hook/string_ext.rb', line 22 def camelcase! to_s.scan(/\w+/).collect(&:capitalize).join end |
#camelize ⇒ Object
31 32 33 |
# File 'lib/site_hook/string_ext.rb', line 31 def camelize dup.camelize! end |
#camelize! ⇒ Object
28 29 30 |
# File 'lib/site_hook/string_ext.rb', line 28 def camelize! to_s.split(/_|\s+/).collect(&:capitalize).join end |
#safe_log_name ⇒ Object
34 35 36 |
# File 'lib/site_hook/string_ext.rb', line 34 def safe_log_name self.split('::').last.underscore end |
#squish ⇒ Object
7 8 9 |
# File 'lib/site_hook/string_ext.rb', line 7 def squish dup.squish! end |
#squish! ⇒ Object
2 3 4 5 6 |
# File 'lib/site_hook/string_ext.rb', line 2 def squish! strip! gsub!(/\s+/, ' ') self end |
#underscore ⇒ Object
19 20 21 |
# File 'lib/site_hook/string_ext.rb', line 19 def underscore dup.underscore! end |
#underscore! ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/site_hook/string_ext.rb', line 10 def underscore! self unless /[A-Z-]|::/.match?(self) self.to_s.gsub!("::".freeze, "/".freeze) self.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze) self.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze) self.tr!("-".freeze, "_".freeze) self.downcase! self end |