Guest User

Untitled

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