Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/ruby-processing/helpers/string.rb
Overview
:nodoc:
Instance Method Summary collapse
- #camelize(first_letter_in_uppercase = true) ⇒ Object
- #humanize ⇒ Object
- #titleize ⇒ Object
- #underscore ⇒ Object
Instance Method Details
#camelize(first_letter_in_uppercase = true) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/ruby-processing/helpers/string.rb', line 11 def camelize(first_letter_in_uppercase = true) if first_letter_in_uppercase self.gsub(/\/(.?)/) { '::' + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } else self.first + self.camelize[1..-1] end end |
#humanize ⇒ Object
7 8 9 |
# File 'lib/ruby-processing/helpers/string.rb', line 7 def humanize() self.gsub(/_id$/, '').gsub(/_/, ' ').capitalize end |
#titleize ⇒ Object
3 4 5 |
# File 'lib/ruby-processing/helpers/string.rb', line 3 def titleize self.underscore.humanize.gsub(/\b([a-z])/) { $1.capitalize } end |
#underscore ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/ruby-processing/helpers/string.rb', line 19 def underscore self.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end |