alexrabarts-tld 0.2.1 → 0.4.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/.gitignore +1 -0
- data/History.txt +9 -0
- data/{README.txt → README.rdoc} +0 -0
- data/Rakefile +51 -15
- data/VERSION.yml +4 -0
- data/lib/tld/tld.rb +11 -8
- data/test/{test_tld.rb → tld_test.rb} +19 -11
- data/tld.gemspec +48 -20
- metadata +21 -23
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/History.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
=== 0.4.0 / 2009-06-30
|
2
|
+
|
3
|
+
* You can now call to_s on a TLD object, which will return the canonical name
|
4
|
+
(i.e. the lowercase extension). This saves you writing code like
|
5
|
+
"foo.co.#{tld.tld}". Instead, now you can write "foo.co.#{tld}".
|
6
|
+
* Addressable::URI is now used for parsing hostnames instead of custom regexes.
|
7
|
+
* Tests now run under Shoulda
|
8
|
+
* The gem is now built under Jeweler instead of Hoe
|
9
|
+
|
1
10
|
=== 0.2.1 / 2009-02-27
|
2
11
|
|
3
12
|
* Bugfix: original strings left intact
|
data/{README.txt → README.rdoc}
RENAMED
File without changes
|
data/Rakefile
CHANGED
@@ -1,20 +1,56 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'hoe'
|
1
|
+
require 'rake'
|
5
2
|
require './lib/tld.rb'
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |s|
|
7
|
+
s.name = 'tld'
|
8
|
+
s.summary = %Q{
|
9
|
+
Provides meta information for Internet Top Level Domains (TLDs).
|
10
|
+
}
|
11
|
+
s.email = "alexrabarts@gmail.com"
|
12
|
+
s.homepage = "http://github.com/alexrabarts/tld"
|
13
|
+
s.description = "Top-level domain library"
|
14
|
+
s.authors = ["alex"]
|
15
|
+
s.add_dependency 'alexrabarts-iso_country_codes', ['>=0.2.1']
|
16
|
+
s.add_dependency 'addressable'
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/rdoctask'
|
23
|
+
Rake::RDocTask.new do |rdoc|
|
24
|
+
rdoc.rdoc_dir = 'rdoc'
|
25
|
+
rdoc.title = 'tld'
|
26
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
27
|
+
rdoc.rdoc_files.include('README*')
|
28
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'rake/testtask'
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
33
|
+
t.libs << 'lib' << 'test'
|
34
|
+
t.pattern = 'test/**/*_test.rb'
|
35
|
+
t.verbose = false
|
36
|
+
end
|
37
|
+
|
38
|
+
begin
|
39
|
+
require 'rcov/rcovtask'
|
40
|
+
Rcov::RcovTask.new do |t|
|
41
|
+
t.libs << 'test'
|
42
|
+
t.test_files = FileList['test/**/*_test.rb']
|
43
|
+
t.verbose = true
|
44
|
+
end
|
45
|
+
rescue LoadError
|
46
|
+
puts "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
13
47
|
end
|
14
48
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
49
|
+
begin
|
50
|
+
require 'cucumber/rake/task'
|
51
|
+
Cucumber::Rake::Task.new(:features)
|
52
|
+
rescue LoadError
|
53
|
+
puts "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
54
|
+
end
|
19
55
|
|
20
|
-
|
56
|
+
task :default => :test
|
data/VERSION.yml
ADDED
data/lib/tld/tld.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'singleton'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'addressable/uri'
|
2
4
|
|
3
5
|
class TLD
|
4
|
-
VERSION = '0.2.1'
|
5
|
-
|
6
6
|
MAP = {
|
7
7
|
:ac => 'sh',
|
8
8
|
:uk => 'gb',
|
@@ -15,6 +15,10 @@ class TLD
|
|
15
15
|
|
16
16
|
class UnknownTldError < StandardError; end
|
17
17
|
|
18
|
+
def to_s
|
19
|
+
tld
|
20
|
+
end
|
21
|
+
|
18
22
|
def tld
|
19
23
|
self.class.tld
|
20
24
|
end
|
@@ -71,12 +75,11 @@ class TLD
|
|
71
75
|
|
72
76
|
alias_method :currency, :main_currency
|
73
77
|
|
74
|
-
def find(
|
75
|
-
|
76
|
-
str.
|
77
|
-
|
78
|
-
|
79
|
-
instance = all.select { |t| t.tld == str }.first
|
78
|
+
def find(str)
|
79
|
+
host = Addressable::URI.heuristic_parse(str).normalized_host.to_s
|
80
|
+
host = str.downcase if host == ''
|
81
|
+
last = host.match(/\./) ? host.split('.').last : host # Take the last one of foo.bar.baz
|
82
|
+
instance = all.select { |t| t.tld == last }.first
|
80
83
|
|
81
84
|
raise UnknownTldError, "TLD '#{str}' unkown." if instance.nil?
|
82
85
|
|
@@ -1,52 +1,60 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'tld'
|
3
|
+
require 'shoulda'
|
3
4
|
|
4
5
|
class TestTld < Test::Unit::TestCase
|
5
|
-
|
6
|
+
should 'find TLD by exact match' do
|
6
7
|
assert_equal 'au', TLD.find('au').tld
|
7
8
|
end
|
8
9
|
|
9
|
-
|
10
|
+
should 'find TLD by exact match with dot' do
|
10
11
|
assert_equal 'au', TLD.find('.au').tld
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
+
should 'find TLD with case' do
|
14
15
|
assert_equal 'au', TLD.find('AU').tld
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
+
should 'find TLD by hostname' do
|
18
19
|
assert_equal 'au', TLD.find('foo.bar.au').tld
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
+
should 'find TLD by url' do
|
22
23
|
assert_equal 'au', TLD.find('http://foo.bar.au/baz').tld
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
+
should 'get TLD currency' do
|
26
27
|
assert_equal 'AUD', TLD.find('au').currency
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
+
should 'get mapped TLD currency' do
|
30
31
|
assert_equal 'EUR', TLD.find('eu').currency
|
31
32
|
assert_equal 'GBP', TLD.find('uk').currency
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
+
should 'get TLD name' do
|
35
36
|
assert_equal 'Australia', TLD.find('au').name
|
36
37
|
assert_equal 'Business', TLD.find('biz').name
|
37
38
|
end
|
38
39
|
|
39
|
-
|
40
|
+
should 'get iso alpha3 code' do
|
40
41
|
assert_equal 'AUS', TLD.find('au').alpha3
|
41
42
|
assert_equal 'GBR', TLD.find('uk').alpha3
|
42
43
|
end
|
43
44
|
|
44
|
-
|
45
|
+
should 'get TLD as a string' do
|
46
|
+
tld = TLD.find('au')
|
47
|
+
|
48
|
+
assert_equal 'au', tld.to_s
|
49
|
+
assert_equal tld.tld, tld.to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
should 'com should map to empty currency (not Comoros)' do
|
45
53
|
assert_equal [], TLD.find('com').currencies
|
46
54
|
assert_nil TLD.find('com').currency
|
47
55
|
end
|
48
56
|
|
49
|
-
|
57
|
+
should 'raise exception when TLD is unknown' do
|
50
58
|
assert_raises TLD::UnknownTldError do
|
51
59
|
TLD.find('foo')
|
52
60
|
end
|
data/tld.gemspec
CHANGED
@@ -2,36 +2,64 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{tld}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.4.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["
|
9
|
-
s.date = %q{2009-
|
10
|
-
s.description = %q{
|
11
|
-
s.email =
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
|
14
|
-
|
15
|
-
s.
|
8
|
+
s.authors = ["alex"]
|
9
|
+
s.date = %q{2009-06-30}
|
10
|
+
s.description = %q{Top-level domain library}
|
11
|
+
s.email = %q{alexrabarts@gmail.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"History.txt",
|
18
|
+
"Manifest.txt",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION.yml",
|
22
|
+
"lib/tld.rb",
|
23
|
+
"lib/tld/alpha3.rb",
|
24
|
+
"lib/tld/cc_tld.rb",
|
25
|
+
"lib/tld/currency.rb",
|
26
|
+
"lib/tld/generic_tld.rb",
|
27
|
+
"lib/tld/infrastructure_tld.rb",
|
28
|
+
"lib/tld/name.rb",
|
29
|
+
"lib/tld/pseudo_tld.rb",
|
30
|
+
"lib/tld/reserved_tld.rb",
|
31
|
+
"lib/tld/retired_tld.rb",
|
32
|
+
"lib/tld/sponsored_tld.rb",
|
33
|
+
"lib/tld/tld.rb",
|
34
|
+
"rakelib/cultivate.rake",
|
35
|
+
"rakelib/tld.rake",
|
36
|
+
"rakelib/tld.rb",
|
37
|
+
"rakelib/tld.rb.erb",
|
38
|
+
"test/tld_test.rb",
|
39
|
+
"tld.gemspec"
|
40
|
+
]
|
41
|
+
s.homepage = %q{http://github.com/alexrabarts/tld}
|
42
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
16
43
|
s.require_paths = ["lib"]
|
17
|
-
s.
|
18
|
-
s.
|
19
|
-
s.
|
20
|
-
|
44
|
+
s.rubygems_version = %q{1.3.4}
|
45
|
+
s.summary = %q{Provides meta information for Internet Top Level Domains (TLDs).}
|
46
|
+
s.test_files = [
|
47
|
+
"test/tld_test.rb"
|
48
|
+
]
|
21
49
|
|
22
50
|
if s.respond_to? :specification_version then
|
23
51
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
-
s.specification_version =
|
52
|
+
s.specification_version = 3
|
25
53
|
|
26
54
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
-
s.add_runtime_dependency(%q<alexrabarts-iso_country_codes>, [">= 0"])
|
28
|
-
s.
|
55
|
+
s.add_runtime_dependency(%q<alexrabarts-iso_country_codes>, [">= 0.2.1"])
|
56
|
+
s.add_runtime_dependency(%q<addressable>, [">= 0"])
|
29
57
|
else
|
30
|
-
s.add_dependency(%q<alexrabarts-iso_country_codes>, [">= 0"])
|
31
|
-
s.add_dependency(%q<
|
58
|
+
s.add_dependency(%q<alexrabarts-iso_country_codes>, [">= 0.2.1"])
|
59
|
+
s.add_dependency(%q<addressable>, [">= 0"])
|
32
60
|
end
|
33
61
|
else
|
34
|
-
s.add_dependency(%q<alexrabarts-iso_country_codes>, [">= 0"])
|
35
|
-
s.add_dependency(%q<
|
62
|
+
s.add_dependency(%q<alexrabarts-iso_country_codes>, [">= 0.2.1"])
|
63
|
+
s.add_dependency(%q<addressable>, [">= 0"])
|
36
64
|
end
|
37
65
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alexrabarts-tld
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- alex
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-30 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,34 +20,33 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 0.2.1
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
type: :
|
26
|
+
name: addressable
|
27
|
+
type: :runtime
|
28
28
|
version_requirement:
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: "0"
|
34
34
|
version:
|
35
|
-
description:
|
36
|
-
email:
|
37
|
-
- alexrabarts@gmail.com
|
35
|
+
description: Top-level domain library
|
36
|
+
email: alexrabarts@gmail.com
|
38
37
|
executables: []
|
39
38
|
|
40
39
|
extensions: []
|
41
40
|
|
42
41
|
extra_rdoc_files:
|
43
|
-
-
|
44
|
-
- Manifest.txt
|
45
|
-
- README.txt
|
42
|
+
- README.rdoc
|
46
43
|
files:
|
44
|
+
- .gitignore
|
47
45
|
- History.txt
|
48
46
|
- Manifest.txt
|
49
|
-
- README.
|
47
|
+
- README.rdoc
|
50
48
|
- Rakefile
|
49
|
+
- VERSION.yml
|
51
50
|
- lib/tld.rb
|
52
51
|
- lib/tld/alpha3.rb
|
53
52
|
- lib/tld/cc_tld.rb
|
@@ -64,14 +63,13 @@ files:
|
|
64
63
|
- rakelib/tld.rake
|
65
64
|
- rakelib/tld.rb
|
66
65
|
- rakelib/tld.rb.erb
|
67
|
-
- test/
|
66
|
+
- test/tld_test.rb
|
68
67
|
- tld.gemspec
|
69
|
-
has_rdoc:
|
70
|
-
homepage:
|
68
|
+
has_rdoc: false
|
69
|
+
homepage: http://github.com/alexrabarts/tld
|
71
70
|
post_install_message:
|
72
71
|
rdoc_options:
|
73
|
-
- --
|
74
|
-
- README.txt
|
72
|
+
- --charset=UTF-8
|
75
73
|
require_paths:
|
76
74
|
- lib
|
77
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -88,10 +86,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
86
|
version:
|
89
87
|
requirements: []
|
90
88
|
|
91
|
-
rubyforge_project:
|
89
|
+
rubyforge_project:
|
92
90
|
rubygems_version: 1.2.0
|
93
91
|
signing_key:
|
94
|
-
specification_version:
|
95
|
-
summary: Provides meta information for Internet Top Level Domains (TLDs)
|
92
|
+
specification_version: 3
|
93
|
+
summary: Provides meta information for Internet Top Level Domains (TLDs).
|
96
94
|
test_files:
|
97
|
-
- test/
|
95
|
+
- test/tld_test.rb
|