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.
@@ -1,3 +1,8 @@
1
+ === 0.6.0 / 2009-06-30
2
+
3
+ * TLD.has_valid_tld? method added, which allows you to check if a given
4
+ hostname has a valid TLD.
5
+
1
6
  === 0.5.0 / 2009-06-30
2
7
 
3
8
  * TLD.valid? method added, which allows you to check if a given string is
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 5
3
- :patch: 0
4
2
  :major: 0
3
+ :minor: 6
4
+ :patch: 0
@@ -76,7 +76,7 @@ class TLD
76
76
  alias_method :currency, :main_currency
77
77
 
78
78
  def find(str)
79
- host = Addressable::URI.heuristic_parse(str).normalized_host.to_s
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
@@ -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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{tld}
5
- s.version = "0.5.0"
5
+ s.version = "0.6.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["alex"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexrabarts-tld
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - alex