Update domain regex to fix last two tests
This commit is contained in:
parent
8fae8cbc1f
commit
57db2afa25
19
lib/swot.rb
19
lib/swot.rb
@ -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
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user