Module: MailMapper
- Defined in:
- lib/mailMapper.rb,
lib/mailMapper/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Method Summary collapse
- #mailMapper(path, option = 0) ⇒ Object
- #mapMails(text = text) ⇒ Object
- #reduceMails(mails = @mails) ⇒ Object
Instance Method Details
#mailMapper(path, option = 0) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mailMapper.rb', line 6 def mailMapper(path, option = 0) text=File.open(path).read if option == 0 @mails = mapMails(text) return reduceMails(@mails) elsif option == 1 mails = mapMails(text) return mapMails(text) elsif option ==2 return mails.each_with_object(Hash.new(0)) { |mail,counts| counts[mail] += 1 } end end |
#mapMails(text = text) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mailMapper.rb', line 19 def mapMails(text=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) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mailMapper.rb', line 31 def 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 } puts @r return @r end |