Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. module Normalizers
  2. module CompanyNormalizer
  3. class NameNormalizer
  4. SUFFIXES = [
  5. ', Inc.',
  6. ', Inc',
  7. 'Inc.',
  8. 'Inc',
  9. ', INC',
  10. ', INC.',
  11. 'INC',
  12. 'INC.',
  13. ', LLC',
  14. 'Limited',
  15. 'LIMITED',
  16. 'GmbH',
  17. 'b.v.',
  18. 'B.V.',
  19. 'GmbH & Co. KG',
  20. ', LTD',
  21. 'LTD',
  22. 'Limited',
  23. 'Pvt. Ltd.',
  24. 'GmbH.',
  25. 'sp. z o.o.',
  26. 'Sp. Z.o.o.',
  27. 'Sp.Z.o.o.',
  28. 'SA',
  29. 's.c.',
  30. 'S.A.',
  31. 'Co',
  32. 'Co.',
  33. 'AS',
  34. 'AB',
  35. '®',
  36. 'doo',
  37. 'plc',
  38. 's.j.',
  39. 'sp.j.',
  40. 'AG',
  41. 'Oy'
  42. ]
  43.  
  44. def normalize(company_name)
  45. SUFFIXES.each do |suffix|
  46. suffix_regex = Regexp.new(normalize_suffix(suffix))
  47. company_name = company_name.gsub(suffix_regex, '')
  48. end
  49. company_name
  50. end
  51.  
  52. def normalize_suffix(suffix)
  53. new_suffix = suffix
  54. if suffix[0] != ',' && suffix != '®'
  55. new_suffix = ' ' + suffix + '$'
  56. end
  57. new_suffix
  58. end
  59. end
  60. end
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement