Module: MailMapper
- Defined in:
- lib/mailMapper.rb,
lib/mailMapper/version.rb
Constant Summary collapse
- VERSION =
"0.1.2"
Class Method Summary collapse
- .find(path = " ", option = 0) ⇒ Object
- .mapMails(text) ⇒ Object
- .reduceMails(mails = @mails) ⇒ Object
Class Method Details
.find(path = " ", option = 0) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 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) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# 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) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 |