Initial commit

This commit is contained in:
Lee Reilly 2012-01-30 20:01:16 -08:00
parent 1ca43ad462
commit c250d18182
7 changed files with 67 additions and 20 deletions

1
.rbenv-version Normal file
View File

@ -0,0 +1 @@
1.9.2-p290

View File

@ -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

25
Gemfile.lock Normal file
View File

@ -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

View File

@ -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.

View File

@ -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'

View File

@ -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

View File

@ -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