Module: CoreExtensions::String

Defined in:
lib/core_extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#slugorizeObject



4
5
6
7
8
9
10
11
12
13
# File 'lib/core_extensions/string.rb', line 4

def slugorize
  result = self.downcase
  result.gsub!(/&([0-9a-z#])+;/, '')  # Ditch Entities
  result.gsub!('&', 'and')            # Replace & with 'and'
  result.gsub!(/[^a-z0-9\-']/, '-')   # Get rid of anything we don't like
  result.gsub!(/-+/, '-')             # collapse dashes
  result.gsub!(/-$/, '')              # trim dashes
  result.gsub!(/^-/, '')              # trim dashes
  result
end

#slugorize!Object



15
16
17
# File 'lib/core_extensions/string.rb', line 15

def slugorize!
  self.replace(self.slugorize)
end