Slugalizer is a one-method Ruby library that can slugalize (or slugify) strings, like this:
Slugalizer.slugalize("Åh, räksmörgåsar!") # => "ah-raksmorgasar"
Defaults to the "-" word separator but can also use "+" or "_":
Slugalizer.slugalize("Åh, räksmörgåsar!", "+") # => "ah+raksmorgasar" Slugalizer.slugalize("Åh, räksmörgåsar!", "_") # => "ah_raksmorgasar"
This library has been incorporated into Ruby on Rails (as
String#parameterize) since 2008-09-23 (Rails 2.2). The library is still of use outside Rails, or with earlier Rails versions. It also has more extensive tests than the code in Rails, and some additional error handling (limited set of word separators, handling non-string input).
Modified by Henrik Nyh.
Released into the public domain.