Module: Slugalizer
- Defined in:
- lib/slugalizer.rb
Class Method Summary collapse
Class Method Details
.to_slug(string = '') ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/slugalizer.rb', line 2 def self.to_slug(string = '') return '' if string.nil? # strip the string ret = string.strip # blow away apostrophes and dots ret.gsub! /['`\.]/,"" # replace all non alphanumeric with dashes ret.gsub! /\s*[^A-Za-z0-9]\s*/, '-' # convert double dashes to single ret.gsub! /-+/,"-" # strip off leading/trailing dashes ret.gsub! /\A[-\.]+|[-\.]+\z/,"" # transform to downcase ret.downcase end |