Created
July 10, 2017 10:45
-
-
Save forresty/1bc4536ebbe4d7601fb3ea717c1f4360 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #require the csv done | |
| #create array done | |
| #extract email address done | |
| #push address into array done | |
| #create a hash done | |
| #for each address in the array | |
| #if in the hash, ++ | |
| #if not, set the value to 1 | |
| #sort the hash by value | |
| #top 5 | |
| require "csv" | |
| addresses = [] | |
| address_hash = {} | |
| counter = 0 | |
| CSV.foreach "Emails.csv" do |row| | |
| row.delete(nil) | |
| row.each do |cell| | |
| email_address = cell.scan(/\A(?:[\w+\-].?)+@[a-z\d\-]+(?:\.[a-z]+)*\.[a-z]+\z/i) | |
| addresses.push(*email_address.map(&:downcase)) | |
| end | |
| counter += 1 | |
| break if counter == 10000 | |
| end | |
| #p addresses | |
| addresses.each do |address| | |
| if address_hash.key?(address) | |
| address_hash[address] += 1 | |
| else | |
| address_hash[address] = 1 | |
| end | |
| end | |
| address_hash = Hash[address_hash.sort_by {|_, value| value }.reverse[0..5]] | |
| p address_hash | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment