Class: MynaBird
- Inherits:
-
Object
show all
- Defined in:
- lib/myna_bird.rb
Defined Under Namespace
Classes: MalformedEmailException
Constant Summary
collapse
- COMMON_LOCALS =
%w(
support info sales marketing admin webmaster help
)
- COMMON_DOMAINS =
%w(
hotmail msn live yahoo yahoo.co.uk ymail rocketmail gmail googlemail aol
fastmail.fm web inbox freemail rediff indiatimes lycos libero.it rambler.ru mac
paracalls linkedin mynet interia.pl yandex sina 126 lycos bol in me
voila.fr mail comcast netcom roadrunner verizon 1and1 att adelphia
bigpond bluebottle blueyonder btopenworld charter cox earthlink sbc telus
mailinator charter rogers sympatico tiscali tmail sbcglobal aim windowslive
juno qq optonline.net mailhaven.com shaw.ca btinternet email orange.fr
frontier.com outlook icloud reliable-mail
) + [
/\.edu$/
]
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(email) ⇒ MynaBird
Returns a new instance of MynaBird.
39
40
41
42
43
44
45
46
|
# File 'lib/myna_bird.rb', line 39
def initialize(email)
raise MalformedEmailException unless email =~ /^[^@]*[a-z0-9][^@]*@[^@]*[a-z0-9][^@]*$/i
@email = email.downcase
@local, @domain = @email.split('@')
end
|
Class Method Details
.avoided_domains ⇒ Object
35
36
37
|
# File 'lib/myna_bird.rb', line 35
def self.avoided_domains
@avoided_domains || []
end
|
.avoided_domains=(domains) ⇒ Object
31
32
33
|
# File 'lib/myna_bird.rb', line 31
def self.avoided_domains=(domains)
@avoided_domains = domains
end
|
.convert(email) ⇒ Object
23
24
25
|
# File 'lib/myna_bird.rb', line 23
def self.convert(email)
new(email).name
end
|
.nameize(str) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/myna_bird.rb', line 72
def self.nameize(str)
name = str.downcase
name.gsub!(/[^a-z0-9]+/, '-')
name.gsub!(/\-$/,'')
name.gsub!(/^\-/,'')
name
end
|
.reset_avoided_domains ⇒ Object
27
28
29
|
# File 'lib/myna_bird.rb', line 27
def self.reset_avoided_domains
@avoided_domains = nil
end
|
Instance Method Details
#avoided_domain? ⇒ Boolean
80
81
82
83
84
|
# File 'lib/myna_bird.rb', line 80
def avoided_domain?
self.class.avoided_domains.any? do |domain|
/#{domain}/.match(@domain)
end
end
|
#common_domain? ⇒ Boolean
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/myna_bird.rb', line 86
def common_domain?
COMMON_DOMAINS.each do |domain|
if domain.is_a?(Regexp)
return true if domain.match(@domain)
elsif domain =~ /\./
return true if /#{domain}$/.match(@domain)
else
return true if /^#{domain}\./.match(@domain)
end
end
return false
end
|
#common_local? ⇒ Boolean
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/myna_bird.rb', line 100
def common_local?
COMMON_LOCALS.each do |local|
if local.is_a?(Regexp)
return true if local.match(@local)
else
return true if local == @local
end
end
return false
end
|
#domain_name ⇒ Object
62
63
64
65
|
# File 'lib/myna_bird.rb', line 62
def domain_name
just_the_host = @domain.split('.').first
self.class.nameize(just_the_host)
end
|
#local_name ⇒ Object
67
68
69
70
|
# File 'lib/myna_bird.rb', line 67
def local_name
local_sans_alias = @local.gsub(/\+.*$/, '')
self.class.nameize(local_sans_alias)
end
|
#name ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/myna_bird.rb', line 50
def name
if common_local? && (common_domain? || avoided_domain?)
local_name + '-at-' + domain_name
elsif common_local?
domain_name
elsif (common_domain? || avoided_domain?)
local_name
else
domain_name
end
end
|