module MailMapper

Constants

VERSION

Public Class Methods

find(path=" ", option = 0) click to toggle source
# File lib/mailMapper.rb, line 6
def self.find(path=" ", option = 0)
        text=File.open(path).read
        if option == 0
                  mails = mapMails(text)   
                  return reduceMails(mails)
                elsif option == 1
                  mails = mapMails(text)      
                  return mails.each_with_object(Hash.new(0)) { |mail,counts| counts[mail] += 1 }      
        elsif option == 2
                  mails = mapMails(text)
          return mapMails(text)
                end   
end
mapMails(text) click to toggle source
# File lib/mailMapper.rb, line 20
def self.mapMails(text)
        mails = []
        #Map text
        line_num=0
        text.gsub!(/\r\n?/, "\n")
        text.each_line do |line|
        mails << line[/[a-zA-Z_]+?@[a-zA-Z_]+?\.[a-zA-Z]{2,3}.[a-zA-Z]{2,3}|[a-zA-Z_]+?@[a-zA-Z_]+?\.[a-zA-Z]{2,3}/]end
        mails.compact!
        # BEGIN map email function
        return mails
end
reduceMails(mails=@mails) click to toggle source
# File lib/mailMapper.rb, line 32
def self.reduceMails(mails=@mails)
    mailExt = []
        mapHash = {}
        domain = ""
        mails.each {|x|
        # Set domain extension (after "@")
        domain = x[/@[a-zA-Z_]+?\.[a-zA-Z]{2,3}.[a-zA-Z]{2,3}|@[a-zA-Z_]+?\.[a-zA-Z]{2,3}/]
        search = mapHash.select{|key, value| key[domain]}
            if search.empty?
               @r = mapHash.merge!({ domain => 1})
            else
                mapHash[domain] += 1 
            end        
        }
        return @r
end