Skip to content

Instantly share code, notes, and snippets.

@forresty
Created July 10, 2017 10:45
Show Gist options
  • Select an option

  • Save forresty/1bc4536ebbe4d7601fb3ea717c1f4360 to your computer and use it in GitHub Desktop.

Select an option

Save forresty/1bc4536ebbe4d7601fb3ea717c1f4360 to your computer and use it in GitHub Desktop.
#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