Sha256: 380ad1dc5ceb4caa59364aa8d6e496be587541a9b32c686b67a772b5b83299a1

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

class MynaBird
  
  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 mail.ru 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
  ) + [
    /\.edu$/
  ]
  
  def self.convert(email)
    new(email).name
  end
  
  def initialize(email)
    @email = email.downcase
    @local, @domain = @email.split('@') 
  end
  
  
  # extract the name
  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
  
  def domain_name
    just_the_host = @domain.split('.').first
    self.class.nameize(just_the_host)
  end
  
  def local_name
    local_sans_alias = @local.gsub(/\+.*$/, '')
    self.class.nameize(local_sans_alias)
  end
  
  def self.nameize(str)
    name = str.downcase
    name.gsub!(/[^a-z0-9]+/, '-')
    name.gsub!(/\-$/,'')
    name.gsub!(/^\-/,'')
    name
  end
  
  def common_domain?
    COMMON_DOMAINS.each do |domain|
      if domain.is_a?(Regexp)
        return true if domain.match(@domain)
      else
        return true if /^#{domain}\./.match(@domain)
      end
    end
   
    return false
  end

  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
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
myna_bird-0.1.0 lib/myna_bird.rb