alexrabarts-tld 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +5 -0
- data/VERSION.yml +2 -2
- data/lib/tld/tld.rb +12 -1
- data/test/tld_test.rb +10 -0
- data/tld.gemspec +1 -1
- metadata +1 -1
data/History.txt
CHANGED
data/VERSION.yml
CHANGED
data/lib/tld/tld.rb
CHANGED
@@ -76,7 +76,7 @@ class TLD
|
|
76
76
|
alias_method :currency, :main_currency
|
77
77
|
|
78
78
|
def find(str)
|
79
|
-
host =
|
79
|
+
host = normalized_host(str)
|
80
80
|
host = str.downcase if host == ''
|
81
81
|
last = host.match(/\./) ? host.split('.').last : host # Take the last one of foo.bar.baz
|
82
82
|
instance = all.select { |t| t.tld == last }.first
|
@@ -86,8 +86,19 @@ class TLD
|
|
86
86
|
instance
|
87
87
|
end
|
88
88
|
|
89
|
+
def has_valid_tld?(str)
|
90
|
+
str = normalized_host(str)
|
91
|
+
str.match(/\./) ? self.valid?(str.split('.').last) : self.valid?(str)
|
92
|
+
end
|
93
|
+
|
89
94
|
def valid?(tld)
|
90
95
|
!!all.select { |t| t.to_s == tld.downcase }.first
|
91
96
|
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def normalized_host(str)
|
101
|
+
Addressable::URI.heuristic_parse(str).normalized_host.to_s
|
102
|
+
end
|
92
103
|
end
|
93
104
|
end
|
data/test/tld_test.rb
CHANGED
@@ -68,4 +68,14 @@ class TestTld < Test::Unit::TestCase
|
|
68
68
|
should 'confirm that TLD is invalid' do
|
69
69
|
assert_equal false, TLD.valid?('not-a-tld')
|
70
70
|
end
|
71
|
+
|
72
|
+
should 'confirm that hostname has a valid TLD' do
|
73
|
+
assert TLD.has_valid_tld?('foo.com.au')
|
74
|
+
assert TLD.has_valid_tld?('http://foo.com.au/bar')
|
75
|
+
end
|
76
|
+
|
77
|
+
should 'confirm that hostname does not have a valid TLD' do
|
78
|
+
assert_equal false, TLD.has_valid_tld?('foo.bar')
|
79
|
+
assert_equal false, TLD.has_valid_tld?('http://foo.bar')
|
80
|
+
end
|
71
81
|
end
|
data/tld.gemspec
CHANGED