Class: MailProvider::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_provider/parser.rb

Constant Summary collapse

FAMOUS_CHECKS =
{
  free: %w[gmail.com hotmail.com outlook.com yahoo.com],
  disposable: %w[mailinator.com temp-mail.ru maildrop.cc 10minutemail.com musicalnr.com]
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



20
21
22
# File 'lib/mail_provider/parser.rb', line 20

def initialize
  @data = { free: [], disposable: [], unknown: [] }
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



18
19
20
# File 'lib/mail_provider/parser.rb', line 18

def key
  @key
end

#pathObject (readonly)

Returns the value of attribute path.



18
19
20
# File 'lib/mail_provider/parser.rb', line 18

def path
  @path
end

Class Method Details

.parse(sources) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/mail_provider/parser.rb', line 10

def self.parse(sources)
  parser = new
  sources.each do |key, path|
    parser.add key, path
  end
  parser.data
end

Instance Method Details

#add(key, path) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/mail_provider/parser.rb', line 24

def add(key, path)
  @key = key
  @path = path

  domains = read_domains_from_source
  type = categorize_source domains
  @data[type] << domains
end

#dataObject



33
34
35
36
37
38
39
40
# File 'lib/mail_provider/parser.rb', line 33

def data
  @data.map do |type, items|
    items = items.flatten.group_by(&:itself)
    items = items.map { |k, v| [k, v.count] }
    items = items.sort_by { |r| r[1] }.reverse
    [type, items.to_h]
  end.to_h.slice(:free, :disposable)
end