lib/myna_bird.rb in myna_bird-0.2.11 vs lib/myna_bird.rb in myna_bird-0.2.12
- old
+ new
@@ -22,10 +22,22 @@
def self.convert(email)
new(email).name
end
+ def self.reset_avoided_domains
+ @avoided_domains = nil
+ end
+
+ def self.avoided_domains=(domains)
+ @avoided_domains = domains
+ end
+
+ def self.avoided_domains
+ @avoided_domains || []
+ end
+
def initialize(email)
# email must be in a somewhat sane format
# i.e. have an @ sign and at least one letter or number on each side of it
raise MalformedEmailException unless email =~ /^[^@]*[a-z0-9][^@]*@[^@]*[a-z0-9][^@]*$/i
@@ -34,15 +46,15 @@
end
# extract the name
def name
- if common_local? && common_domain?
+ if common_local? && (common_domain? || avoided_domain?)
local_name + '-at-' + domain_name
elsif common_local?
domain_name
- elsif common_domain?
+ elsif (common_domain? || avoided_domain?)
local_name
else
domain_name
end
end
@@ -61,9 +73,15 @@
name = str.downcase
name.gsub!(/[^a-z0-9]+/, '-')
name.gsub!(/\-$/,'')
name.gsub!(/^\-/,'')
name
+ end
+
+ def avoided_domain?
+ self.class.avoided_domains.any? do |domain|
+ /#{domain}/.match(@domain)
+ end
end
def common_domain?
COMMON_DOMAINS.each do |domain|
if domain.is_a?(Regexp)