Train-driven development 🚋
This commit is contained in:
parent
505287aaa4
commit
f633e573be
28
README.rdoc
28
README.rdoc
@ -1,22 +1,22 @@
|
||||
= email
|
||||
|
||||
Identify email addresses associated with educational institutions throughout the world which provide higher education in tertiary, quaternary and post-secondary education.
|
||||
Swot allows you to figure out whether a particular email address or domain
|
||||
is associated with an academic institution providing higher education in
|
||||
tertiary, quaternary and post-secondary education.
|
||||
|
||||
== Email addresses belonging to academic institutions
|
||||
|
||||
Email::academic?('lreilly@stanford.edu') # true
|
||||
Email::academic?('lreilly@slac.stanford.edu') # true
|
||||
Email::academic?('lreilly@strath.ac.uk') # true
|
||||
Email::academic?('lreilly@soft-eng.strath.ac.uk') # true
|
||||
Email::academic?('lee@ugr.es') # true
|
||||
Email::academic?('lee@uottawa.ca') # true
|
||||
Swot::academic?('lreilly@stanford.edu') # true
|
||||
Swot::academic?('lreilly@slac.stanford.edu') # true
|
||||
Swot::academic?('lreilly@strath.ac.uk') # true
|
||||
Swot::academic?('lreilly@soft-eng.strath.ac.uk') # true
|
||||
Swot::academic?('lee@ugr.es') # true
|
||||
Swot::academic?('lee@uottawa.ca') # true
|
||||
|
||||
== Email addresses not belonging to academic institutions
|
||||
|
||||
Email::academic?('lee@leerilly.net') # false
|
||||
Email::academic?('lee@gmail.com') # false
|
||||
Email::academic?('lee@stanford.edu.com') # false
|
||||
Email::academic?('lee@strath.ac.uk.com') # false
|
||||
Swot::academic?('lee@leerilly.net') # false
|
||||
Swot::academic?('lee@gmail.com') # false
|
||||
Swot::academic?('lee@stanford.edu.com') # false
|
||||
Swot::academic?('lee@strath.ac.uk.com') # false
|
||||
|
||||
* is this email address from an academic institution?
|
||||
|
||||
@ -30,6 +30,8 @@ Identify email addresses associated with educational institutions throughout the
|
||||
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
||||
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
||||
|
||||
== Known Issues / Bugs
|
||||
|
||||
== Copyright
|
||||
|
||||
Copyright (c) 2012 Lee Reilly. See LICENSE.txt for
|
||||
|
||||
6
Rakefile
6
Rakefile
@ -14,8 +14,8 @@ require 'rake'
|
||||
require 'jeweler'
|
||||
Jeweler::Tasks.new do |gem|
|
||||
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
||||
gem.name = "email"
|
||||
gem.homepage = "http://github.com/leereilly/email"
|
||||
gem.name = "swot"
|
||||
gem.homepage = "http://github.com/leereilly/swot"
|
||||
gem.license = "MIT"
|
||||
gem.summary = %Q{email helpers}
|
||||
gem.description = %Q{email helpers}
|
||||
@ -39,7 +39,7 @@ Rake::RDocTask.new do |rdoc|
|
||||
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
||||
|
||||
rdoc.rdoc_dir = 'rdoc'
|
||||
rdoc.title = "email #{version}"
|
||||
rdoc.title = "swot #{version}"
|
||||
rdoc.rdoc_files.include('README*')
|
||||
rdoc.rdoc_files.include('lib/**/*.rb')
|
||||
end
|
||||
|
||||
125
lib/swot.rb
Normal file
125
lib/swot.rb
Normal file
@ -0,0 +1,125 @@
|
||||
require 'public_suffix'
|
||||
|
||||
module Swot
|
||||
VERSION = "0.1.0"
|
||||
|
||||
# These top-level domains are guaranteed to be academic instituions.
|
||||
ACADEMIC_TLDS = [
|
||||
'ac.uk',
|
||||
'edu',
|
||||
'edu.af',
|
||||
'edu.al',
|
||||
'edu.ar',
|
||||
'edu.au',
|
||||
'edu.az',
|
||||
'edu.ba',
|
||||
'edu.bb',
|
||||
'edu.bd',
|
||||
'edu.bh',
|
||||
'edu.bi',
|
||||
'edu.bn',
|
||||
'edu.bo',
|
||||
'edu.br',
|
||||
'edu.bs',
|
||||
'edu.bt',
|
||||
'edu.bz',
|
||||
'edu.cn',
|
||||
'edu.co',
|
||||
'edu.cu',
|
||||
'edu.do',
|
||||
'edu.dz',
|
||||
'edu.ec',
|
||||
'edu.ee',
|
||||
'edu.eg',
|
||||
'edu.er',
|
||||
'edu.es',
|
||||
'edu.et',
|
||||
'edu.ge',
|
||||
'edu.gh',
|
||||
'edu.gr',
|
||||
'edu.gt',
|
||||
'edu.hk',
|
||||
'edu.hn',
|
||||
'edu.ht',
|
||||
'edu.iq',
|
||||
'edu.jm',
|
||||
'edu.jo',
|
||||
'edu.kg',
|
||||
'edu.kh',
|
||||
'edu.kn',
|
||||
'edu.kw',
|
||||
'edu.ky',
|
||||
'edu.kz',
|
||||
'edu.la',
|
||||
'edu.lb',
|
||||
'edu.lv',
|
||||
'edu.ly',
|
||||
'edu.mk',
|
||||
'edu.mm',
|
||||
'edu.mn',
|
||||
'edu.mo',
|
||||
'edu.mt',
|
||||
'edu.mx',
|
||||
'edu.my',
|
||||
'edu.ni',
|
||||
'edu.np',
|
||||
'edu.om',
|
||||
'edu.pa',
|
||||
'edu.pe',
|
||||
'edu.ph',
|
||||
'edu.pk',
|
||||
'edu.pl',
|
||||
'edu.pr',
|
||||
'edu.ps',
|
||||
'edu.pt',
|
||||
'edu.py',
|
||||
'edu.qa',
|
||||
'edu.rs',
|
||||
'edu.ru',
|
||||
'edu.sa',
|
||||
'edu.sd',
|
||||
'edu.sg',
|
||||
'edu.sv',
|
||||
'edu.sy',
|
||||
'edu.tr',
|
||||
'edu.tt',
|
||||
'edu.tw',
|
||||
'edu.ua',
|
||||
'edu.uy',
|
||||
'edu.ve',
|
||||
'edu.vn',
|
||||
'edu.ws',
|
||||
'edu.ye',
|
||||
'edu.zm',
|
||||
'vic.edu.au'
|
||||
]
|
||||
|
||||
class << self
|
||||
|
||||
# Figure out if an email or domain belongs to academic instituion.
|
||||
#
|
||||
# Returns true if the domain name belongs to an academic institution;
|
||||
# false oterwise.
|
||||
def is_academic?(text)
|
||||
text = text.split("@")[1] if text.include? "@"
|
||||
domain = PublicSuffix.parse(text)
|
||||
|
||||
if ACADEMIC_TLDS.include?(domain.tld)
|
||||
true
|
||||
elsif match_academic_domain?(domain)
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Figure out if a domain name is a know academic institution.
|
||||
#
|
||||
# Returns true if the domain name belongs to a known academic instition;
|
||||
# false otherwise.
|
||||
def match_academic_domain?(domain)
|
||||
File.exists?("lib/domains/#{domain.tld}/#{domain.sld}")
|
||||
end
|
||||
end
|
||||
end
|
||||
5911
swot.gemspec
Normal file
5911
swot.gemspec
Normal file
File diff suppressed because it is too large
Load Diff
@ -12,7 +12,7 @@ require 'shoulda'
|
||||
|
||||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
||||
require 'email'
|
||||
require 'swot'
|
||||
|
||||
class Test::Unit::TestCase
|
||||
end
|
||||
|
||||
@ -1,20 +1,34 @@
|
||||
require 'helper'
|
||||
|
||||
class TestEmail < Test::Unit::TestCase
|
||||
should "know what a valid educational institution email address is" do
|
||||
assert_equal Email::academic?('lreilly@stanford.edu'), true
|
||||
assert_equal Email::academic?('lreilly@slac.stanford.edu'), true
|
||||
assert_equal Email::academic?('lreilly@strath.ac.uk'), true
|
||||
assert_equal Email::academic?('lreilly@soft-eng.strath.ac.uk'), true
|
||||
assert_equal Email::academic?('lee@ugr.es'), true
|
||||
assert_equal Email::academic?('lee@uottawa.ca'), true
|
||||
assert_equal Email::academic?('lee@leerilly.net'), false
|
||||
assert_equal Email::academic?('lee@gmail.com'), false
|
||||
assert_equal Email::academic?('lee@stanford.edu.com'), false
|
||||
assert_equal Email::academic?('lee@strath.ac.uk.com'), false
|
||||
end
|
||||
should "know what a valid acadmic institution email address or domain is" do
|
||||
assert_equal Swot::is_academic?('lreilly@stanford.edu'), true
|
||||
assert_equal Swot::is_academic?('lreilly@slac.stanford.edu'), true
|
||||
assert_equal Swot::is_academic?('lreilly@strath.ac.uk'), true
|
||||
assert_equal Swot::is_academic?('lreilly@soft-eng.strath.ac.uk'), true
|
||||
assert_equal Swot::is_academic?('lee@ugr.es'), true
|
||||
assert_equal Swot::is_academic?('lee@uottawa.ca'), true
|
||||
assert_equal Swot::is_academic?('lee@mother.edu.ru'), true
|
||||
assert_equal Swot::is_academic?('lee@ucy.ac.cy'), true
|
||||
|
||||
assert_equal Swot::is_academic?('lee@leerilly.net'), false
|
||||
assert_equal Swot::is_academic?('lee@gmail.com'), false
|
||||
assert_equal Swot::is_academic?('lee@stanford.edu.com'), false
|
||||
assert_equal Swot::is_academic?('lee@strath.ac.uk.com'), false
|
||||
|
||||
assert_equal Swot::is_academic?('stanford.edu'), true
|
||||
assert_equal Swot::is_academic?('slac.stanford.edu'), true
|
||||
assert_equal Swot::is_academic?('strath.ac.uk'), true
|
||||
assert_equal Swot::is_academic?('soft-eng.strath.ac.uk'), true
|
||||
assert_equal Swot::is_academic?('ugr.es'), true
|
||||
assert_equal Swot::is_academic?('uottawa.ca'), true
|
||||
assert_equal Swot::is_academic?('mother.edu.ru'), true
|
||||
assert_equal Swot::is_academic?('ucy.ac.cy'), true
|
||||
|
||||
assert_equal Swot::is_academic?('leerilly.net'), false
|
||||
assert_equal Swot::is_academic?('gmail.com'), false
|
||||
assert_equal Swot::is_academic?('stanford.edu.com'), false
|
||||
assert_equal Swot::is_academic?('strath.ac.uk.com'), false
|
||||
|
||||
should "should populate academic domains" do
|
||||
Email::populate_academic_domains
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user