Module: PrettyParam
- Defined in:
- lib/pretty_param.rb,
lib/pretty_param/version.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
"1.1.1"
Class Method Summary collapse
-
.escape(string) ⇒ Object
This method does the actual permalink escaping.
Class Method Details
.escape(string) ⇒ Object
This method does the actual permalink escaping.
4 5 6 7 8 9 10 11 |
# File 'lib/pretty_param.rb', line 4 def escape(string) result = string result.gsub!(/[^\x00-\x7F]+/, '') # Remove anything non-ASCII entirely (e.g. diacritics). result.gsub!(/[^\w_ \-]+/i, '') # Remove unwanted chars. result.gsub!(/[ \-]+/i, '-') # No more than one of the separator in a row. result.gsub!(/^\-|\-$/i, '') # Remove leading/trailing separator. result.downcase end |