Update domain regex to fix last two tests

This commit is contained in:
Chris Hunt 2013-05-28 17:54:40 -07:00
parent 8fae8cbc1f
commit 57db2afa25
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