Merge pull request #29 from chrishunt/chrishunt/fix-tests

Update domain regex to fix last two tests
This commit is contained in:
Lee Reilly 2013-05-28 19:13:38 -07:00
commit 7efeb4437d
2 changed files with 11 additions and 12 deletions

View File

@ -191,17 +191,16 @@ module Swot
#
# Returns a string with the FQDN; nil if there's an error.
def get_domain(text)
text.strip!
return false if text.nil?
text.downcase!
text = text.split("@")[1] if text.include? "@"
PublicSuffix.parse text.downcase.match(domain_regex).captures.first
rescue
return nil
end
begin
domain = PublicSuffix.parse(text)
return domain
rescue
return nil
end
private
# http://rubular.com/r/uW2GqSxvqD
def domain_regex
/([^@\/:]+)[:\d]*$/
end
end
end

View File

@ -21,8 +21,8 @@ class TestEmail < Test::Unit::TestCase
assert_equal Swot::is_academic?('stanford.edu'), true
assert_equal Swot::is_academic?('slac.stanford.edu'), true
assert_equal Swot::is_academic?('www.stanford.edu'), true
#assert_equal Swot::is_academic?('http://www.stanford.edu'), true
#assert_equal Swot::is_academic?('http://www.stanford.edu:9393'), true
assert_equal Swot::is_academic?('http://www.stanford.edu'), true
assert_equal Swot::is_academic?('http://www.stanford.edu:9393'), 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