Class: String

Inherits:
Object show all
Defined in:
lib/plugins/string_extensions/lib/string_extensions.rb

Instance Method Summary collapse

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

#symbolizeObject



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

#titlecaseObject



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