diff --git a/.rbenv-version b/.rbenv-version new file mode 100644 index 0000000000..0a95b9f5c7 --- /dev/null +++ b/.rbenv-version @@ -0,0 +1 @@ +1.9.2-p290 diff --git a/Gemfile b/Gemfile index 330b36a3cd..a29a618478 100644 --- a/Gemfile +++ b/Gemfile @@ -1,14 +1,10 @@ source "http://rubygems.org" -# Add dependencies required to use your gem here. -# Example: -# gem "activesupport", ">= 2.3.5" -# Add dependencies to develop your gem here. -# Include everything needed to run rake, tests, features, etc. +gem 'public_suffix' + group :development do gem "shoulda", ">= 0" gem "rdoc", "~> 3.12" gem "bundler", "~> 1.0.0" gem "jeweler", "~> 1.8.3" - gem "rcov", ">= 0" end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..ab33079164 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,25 @@ +GEM + remote: http://rubygems.org/ + specs: + git (1.2.5) + jeweler (1.8.3) + bundler (~> 1.0) + git (>= 1.2.5) + rake + rdoc + json (1.6.5) + public_suffix (1.0.0) + rake (0.9.2.2) + rdoc (3.12) + json (~> 1.4) + shoulda (2.11.3) + +PLATFORMS + ruby + +DEPENDENCIES + bundler (~> 1.0.0) + jeweler (~> 1.8.3) + public_suffix + rdoc (~> 3.12) + shoulda diff --git a/README.rdoc b/README.rdoc index 24c79384e1..db3dbc3164 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,9 +1,11 @@ = email -Description goes here. +Helpers for email addresses. + +* is this email address from an academic institution? == Contributing to email - + * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet. * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it. * Fork the project. diff --git a/Rakefile b/Rakefile index 871c8b287e..749b279659 100644 --- a/Rakefile +++ b/Rakefile @@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem| gem.name = "email" gem.homepage = "http://github.com/leereilly/email" gem.license = "MIT" - gem.summary = %Q{TODO: one-line summary of your gem} - gem.description = %Q{TODO: longer description of your gem} + gem.summary = %Q{email helpers} + gem.description = %Q{email helpers} gem.email = "lee@leereilly.net" gem.authors = ["Lee Reilly"] # dependencies defined in Gemfile @@ -32,14 +32,6 @@ Rake::TestTask.new(:test) do |test| test.verbose = true end -require 'rcov/rcovtask' -Rcov::RcovTask.new do |test| - test.libs << 'test' - test.pattern = 'test/**/test_*.rb' - test.verbose = true - test.rcov_opts << '--exclude "gems/*"' -end - task :default => :test require 'rdoc/task' diff --git a/lib/email.rb b/lib/email.rb index e69de29bb2..4818304214 100644 --- a/lib/email.rb +++ b/lib/email.rb @@ -0,0 +1,22 @@ +require 'public_suffix' + +module Email + VERSION = "0.0.1" + + ACADEMIC_TLDS = %w(edu ac.uk) + ACADEMIC_DOMAINS = %w(ugr.es uottawa.ca) + + class << self + def academic?(email) + domain = PublicSuffix.parse(email.split("@")[1]) + + if ACADEMIC_TLDS.include?(domain.tld) + true + elsif ACADEMIC_DOMAINS.include? (domain.domain) + true + else + false + end + end +end +end \ No newline at end of file diff --git a/test/test_email.rb b/test/test_email.rb index 01f07516b4..6b08bfb25f 100644 --- a/test/test_email.rb +++ b/test/test_email.rb @@ -1,7 +1,16 @@ require 'helper' class TestEmail < Test::Unit::TestCase - should "probably rename this file and start testing for real" do - flunk "hey buddy, you should probably rename this file and start testing for real" + 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 end