Module: Permalink
- Defined in:
- lib/permalink.rb
Class Method Summary collapse
Class Method Details
.from(string) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/permalink.rb', line 5 def self.from(string) # Remove chars with accents string = if "".encoding_aware? UnicodeUtils.nfkd(string).gsub(/[^\x00-\x7F]/,'').downcase.to_s else string.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n,'').downcase.to_s end # Remove any non alphanumeric chars string.gsub("&", "and"). gsub(/[^a-z0-9\-_]/i, '-'). gsub(/-{2,}/, '-'). gsub(/(^-+|-+$)/, '') end |