Module: Ampersat
- Defined in:
- lib/ampersat.rb,
lib/ampersat/cli.rb,
lib/ampersat/version.rb
Defined Under Namespace
Classes: CLI
Constant Summary collapse
- VERSION =
'1.0.1'
Class Method Summary collapse
- .domains(email_list, column = 0) ⇒ Object
- .find_domain(email) ⇒ Object
- .find_mx(domain) ⇒ Object
- .mxs(email_list, column = 0) ⇒ Object
Class Method Details
.domains(email_list, column = 0) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ampersat.rb', line 9 def self.domains(email_list, column=0) domains = Hash.new(0) CSV.foreach(email_list) do |row| domain = Ampersat.find_domain(row[column]) domains[domain] = domains[domain] + 1 end domains.sort_by {|key, value| - value} end |
.find_domain(email) ⇒ Object
37 38 39 |
# File 'lib/ampersat.rb', line 37 def self.find_domain(email) email.split('@').last.downcase end |
.find_mx(domain) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ampersat.rb', line 41 def self.find_mx(domain) @mxs ||= {} @mxs[domain] ||= begin Resolv::DNS.open(nameserver: '8.8.8.8') do |dns| next unless PublicSuffix.valid?(domain) response = dns.getresources(domain, Resolv::DNS::Resource::IN::MX) next unless response.any? response.collect { |r| r.exchange.to_s.downcase }.sort.first end end end |
.mxs(email_list, column = 0) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ampersat.rb', line 20 def self.mxs(email_list, column=0) mxs = {} domains = Ampersat.domains(email_list, column) = ProgressBar.create(format: '%t: %c / %C |%B|', starting_at: 0, total: domains.length) domains.pmap(100) do |domain, qty| mx = Ampersat.find_mx(domain) mxs[mx] ||= {} mxs[mx]['domains'] ||= [] mxs[mx]['domains'] << domain mxs[mx]['addresses'] ||= 0 mxs[mx]['addresses'] = mxs[mx]['addresses'] + qty .increment end mxs.sort_by {|key, value| - value['addresses'] } end |