Class: String
- Defined in:
- lib/plugins/string_extensions/lib/string_extensions.rb
Instance Method Summary collapse
- #parameterize(sep = '-') ⇒ Object (also: #to_slug, #slugify, #slugerize)
- #symbolize ⇒ Object
- #titlecase ⇒ Object
- #to_name(last_part = '') ⇒ Object
Instance Method Details
#parameterize(sep = '-') ⇒ Object Also known as: to_slug, slugify, slugerize
15 16 17 |
# File 'lib/plugins/string_extensions/lib/string_extensions.rb', line 15 def parameterize(sep = '-') ActiveSupport::Inflector.parameterize(self, sep) end |
#symbolize ⇒ Object
2 3 4 |
# File 'lib/plugins/string_extensions/lib/string_extensions.rb', line 2 def symbolize self.gsub(/[^A-Za-z0-9]+/, "_").gsub(/(^_+|_+$)/, "").underscore.to_sym end |
#titlecase ⇒ Object
6 7 8 |
# File 'lib/plugins/string_extensions/lib/string_extensions.rb', line 6 def titlecase self.gsub(/((?:^|\s)[a-z])/) { $1.upcase } end |
#to_name(last_part = '') ⇒ Object
10 11 12 |
# File 'lib/plugins/string_extensions/lib/string_extensions.rb', line 10 def to_name(last_part = '') self.underscore.gsub('/', ' ').humanize.titlecase.gsub(/\s*#{last_part}$/, '') end |