Posted By

javierarce on 03/20/08


Tagged

textmate rails ruby tokenize permalink


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


tokenize


 / Published in: Rails
 

  1. def tokenize
  2. result = self.name.gsub(/[�����]/, 'a')
  3. result.gsub!(/[����]/, 'e')
  4. result.gsub!(/[����]/, 'i')
  5. result.gsub!(/[����]/, 'o')
  6. result.gsub!(/[����]/, 'u')
  7. result.gsub!(/[�Ÿ]/, 'y')
  8. result.gsub!(/[�]/, 'n')
  9. result.gsub!(/[�]/, 'c')
  10.  
  11. result = result.downcase
  12.  
  13. result.gsub!(/[áà äâå]/, 'a')
  14. result.gsub!(/[éèëê]/, 'e')
  15. result.gsub!(/[íìïî]/, 'i')
  16. result.gsub!(/[óòöô]/, 'o')
  17. result.gsub!(/[úùüû]/, 'u')
  18. result.gsub!(/[ýÿ]/, 'y')
  19. result.gsub!(/[ñ]/, 'n')
  20. result.gsub!(/[ç]/, 'c')
  21. result.gsub!(/['"]/, '-')
  22. result.gsub!(/ +/, '-')
  23. result.gsub!(/_/, '-')
  24. result.gsub!(/(_)$/, '-')
  25. result.gsub!(/^(_)/, '-')
  26. result.gsub!(/W+/, '-') # all non-word chars are removed
  27. result.gsub!(/-Z/, '')
  28. self.permalink = result
  29. end

Report this snippet  

You need to login to post a comment.