Guest User

Untitled

a guest
Feb 20th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. inworksheet.each() { |row|
  2. begin
  3. linecounter = linecounter + 1
  4.  
  5. address = row.at(0).to_s('latin1') if (row.is_a?(Array))
  6. rescue
  7. errors = true
  8. print "\nThere is a problem on line ", linecounter, " that could not be automatically solved. Please check in the source file.\n"
  9. next
  10. end
  11.  
  12. unless (address == nil)
  13. #correct emailaddresses:
  14. address = address.strip
  15. address = address.gsub(/\s/, "")
  16.  
  17. email = address[/[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})/]
  18.  
  19. if (email != nil)
  20. namepart = email.split(/@/)
  21. domain = namepart[1]
  22. if (namepart[0] != nil)
  23. names = namepart[0].split(/[._-]/)
  24. names.compact
  25. names.delete_if {|x| x =="."}
  26. names.delete_if {|x| x =="_"}
  27. names.delete_if {|x| x =="-"}
  28. names = names.collect! {|name|
  29. name.capitalize
  30. }
  31. names.each{|name|
  32. outworksheet.write(linecounter, names.index(name)+2, name)
  33. }
  34. end
  35.  
  36. if (domain != nil)
  37. country = Countrycodes[domain.split(".").last.upcase]
  38. outworksheet.write(linecounter, 1, country, format)
  39. end
  40.  
  41. outworksheet.write(successcounter, 0, email, format)
  42.  
  43. successcounter = successcounter + 1
  44. elsif (address == "")
  45. emptycounter = emptycounter + 1
  46. else
  47. failedcounter = failedcounter + 1
  48. puts address
  49. end
  50. totalcounter = totalcounter + 1
  51. end
  52. }
Add Comment
Please, Sign In to add comment