Test case sensitivity
This commit is contained in:
parent
367c36d244
commit
7e652bce3a
27
lib/swot.rb
27
lib/swot.rb
@ -101,17 +101,28 @@ module Swot
|
||||
# Returns true if the domain name belongs to an academic institution;
|
||||
# false oterwise.
|
||||
def is_academic?(text)
|
||||
return false if text.nil?
|
||||
|
||||
text.downcase!
|
||||
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
|
||||
begin
|
||||
domain = PublicSuffix.parse(text)
|
||||
|
||||
if ACADEMIC_TLDS.include?(domain.tld)
|
||||
true
|
||||
elsif match_academic_domain?(domain)
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
|
||||
rescue PublicSuffix::DomainInvalid => di
|
||||
return false
|
||||
|
||||
rescue PublicSuffix::DomainNotAllowed => dna
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Figure out if a domain name is a know academic institution.
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
require 'helper'
|
||||
|
||||
class TestEmail < Test::Unit::TestCase
|
||||
should "work with all the things" do
|
||||
should "recognizes academic email addresses and domains" do
|
||||
assert_equal Swot::is_academic?('lreilly@stanford.edu'), true
|
||||
assert_equal Swot::is_academic?('LREILLY@STANFORD.EDU'), true
|
||||
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
|
||||
@ -33,5 +35,9 @@ class TestEmail < Test::Unit::TestCase
|
||||
assert_equal Swot::is_academic?('stanford.edu.com'), false
|
||||
assert_equal Swot::is_academic?('strath.ac.uk.com'), false
|
||||
|
||||
assert_equal Swot::is_academic?(nil), false
|
||||
assert_equal Swot::is_academic?(''), false
|
||||
assert_equal Swot::is_academic?('the'), false
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user