Class: WebmailProvider

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url) ⇒ WebmailProvider

Returns a new instance of WebmailProvider.



7
8
9
10
# File 'lib/webmail_provider.rb', line 7

def initialize(name, url)
  @name = name
  @url  = URI("https://#{url}")
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/webmail_provider.rb', line 5

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/webmail_provider.rb', line 5

def url
  @url
end

Class Method Details

.for(email_address) ⇒ Object



12
13
14
15
# File 'lib/webmail_provider.rb', line 12

def self.for(email_address)
  domain = email_address && email_address.split('@').last.to_s.strip
  list[domain]
end

.listObject



17
18
19
20
21
22
# File 'lib/webmail_provider.rb', line 17

def self.list
  @list ||= CSV.foreach(File.join(__dir__, 'providers.csv'))
               .each_with_object({}) do |(domain, *attributes), hash|
                 hash[domain] = new(*attributes)
               end
end