Module: Angus::String
- Defined in:
- lib/angus/utils/string.rb
Class Method Summary collapse
Class Method Details
.camelize(term, uppercase_first_letter = true) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/angus/utils/string.rb', line 14 def camelize(term, uppercase_first_letter = true) string = term.to_s if uppercase_first_letter string = string.sub(/^[a-z\d]*/) { $&.capitalize } else string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase } end string.gsub(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }.gsub('/', '::') end |
.underscore(string) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/angus/utils/string.rb', line 6 def underscore(string) string.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr('-', '_'). downcase end |