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.ru 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.com
) + [
/\.edu$/
]
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(email) ⇒ MynaBird
Returns a new instance of MynaBird.
27
28
29
30
31
32
33
34
|
# File 'lib/myna_bird.rb', line 27
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
.convert(email) ⇒ Object
23
24
25
|
# File 'lib/myna_bird.rb', line 23
def self.convert(email)
new(email).name
end
|
.nameize(str) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/myna_bird.rb', line 60
def self.nameize(str)
name = str.downcase
name.gsub!(/[^a-z0-9]+/, '-')
name.gsub!(/\-$/,'')
name.gsub!(/^\-/,'')
name
end
|
Instance Method Details
#common_domain? ⇒ Boolean
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/myna_bird.rb', line 68
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
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/myna_bird.rb', line 82
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
50
51
52
53
|
# File 'lib/myna_bird.rb', line 50
def domain_name
just_the_host = @domain.split('.').first
self.class.nameize(just_the_host)
end
|
#local_name ⇒ Object
55
56
57
58
|
# File 'lib/myna_bird.rb', line 55
def local_name
local_sans_alias = @local.gsub(/\+.*$/, '')
self.class.nameize(local_sans_alias)
end
|
#name ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/myna_bird.rb', line 38
def name
if common_local? && common_domain?
local_name + '-at-' + domain_name
elsif common_local?
domain_name
elsif common_domain?
local_name
else
domain_name
end
end
|