Module: Normailize::Provider

Included in:
Generic, Gmail, Hotmail, Live
Defined in:
lib/normailize/provider.rb,
lib/normailize/provider/live.rb,
lib/normailize/provider/gmail.rb,
lib/normailize/provider/generic.rb,
lib/normailize/provider/hotmail.rb

Overview

Public: Module to give email provider classes default functionality

Defined Under Namespace

Modules: ClassMethods Classes: Generic, Gmail, Hotmail, Live

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.factory(domain) ⇒ Object

Internal: Create a provider instance from a domain

domain - A domain for an email provider, like gmail.com

Returns an instance of a provider that recognizes the domain or a generic provider



12
13
14
15
16
17
18
19
# File 'lib/normailize/provider.rb', line 12

def self.factory(domain)
  case domain
  when *Gmail.domains   then Gmail.new(domain)
  when *Live.domains    then Live.new(domain)
  when *Hotmail.domains then Hotmail.new(domain)
  else Generic.new(domain)
  end
end

.included(base) ⇒ Object



21
22
23
24
# File 'lib/normailize/provider.rb', line 21

def self.included(base)
  class << base; attr_accessor :domains, :modifications end
  base.extend(ClassMethods)    
end

Instance Method Details

#domainObject

Internal: Get the domain that the provider was instantiated with

Returns domain



81
82
83
# File 'lib/normailize/provider.rb', line 81

def domain
  @domain
end

#generic?Boolean

Internal: Determine if a provider is generic or not

Returns true if generic or false if not

Returns:

  • (Boolean)


88
89
90
# File 'lib/normailize/provider.rb', line 88

def generic?
  self.is_a?(Normailize::Provider::Generic)
end

#initialize(domain) ⇒ Object

Public: Class initializer

domain - A domain like gmail.com

Returns nothing



66
67
68
# File 'lib/normailize/provider.rb', line 66

def initialize(domain)
  @domain = domain
end

#modificationsObject

Internal: Get all modification rules for the provider

Returns symbols that tell the email class how to normalize an address for the provider



74
75
76
# File 'lib/normailize/provider.rb', line 74

def modifications
  self.class.modifications || []
end

#same_as?(provider) ⇒ Boolean

Internal: Determine if two providers are the same or not

provider - An instance of another provider class

Returns true if providers are the same or false if not

Returns:

  • (Boolean)


97
98
99
100
101
102
103
# File 'lib/normailize/provider.rb', line 97

def same_as?(provider)
  if self.generic? || provider.generic?
    @domain == provider.domain
  else
    self.class == provider.class
  end
end