Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string_extensions/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
17 18 19 |
# File 'lib/string_extensions/string_extensions.rb', line 17 def parameterize(sep = '-') remove_formatting.downcase.replace_whitespace(sep).collapse(sep) end |
#symbolize ⇒ Object
4 5 6 |
# File 'lib/string_extensions/string_extensions.rb', line 4 def symbolize gsub(/[^A-Za-z0-9]+/, '_').gsub(/(^_+|_+$)/, '').underscore.to_sym end |
#titlecase ⇒ Object
8 9 10 |
# File 'lib/string_extensions/string_extensions.rb', line 8 def titlecase gsub(/((?:^|\s)[a-z])/) { $1.to_s.upcase } end |
#to_name(last_part = '') ⇒ Object
12 13 14 |
# File 'lib/string_extensions/string_extensions.rb', line 12 def to_name(last_part = '') underscore.gsub('/', ' ').humanize.titlecase.gsub(/\s*#{last_part}$/, '') end |