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 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
File without changes
data/Rakefile CHANGED
@@ -1,20 +1,56 @@
1
- # -*- ruby -*-
2
-
3
- require 'rubygems'
4
- require 'hoe'
1
+ require 'rake'
5
2
  require './lib/tld.rb'
6
3
 
7
- Hoe.new('tld', TLD::VERSION) do |p|
8
- # p.rubyforge_name = 'TLDx' # if different than lowercase project name
9
- p.developer('Alex Rabarts', 'alexrabarts@gmail.com')
10
- p.extra_deps = [
11
- ['alexrabarts-iso_country_codes']
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
- # Load extra rake tasks.
16
- tasks_path = File.join(File.dirname(__FILE__), 'rakelib')
17
- rake_files = Dir["#{tasks_path}/*.rake"]
18
- rake_files.each{|rake_file| load rake_file}
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
- # vim: syntax=Ruby
56
+ task :default => :test
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 4
3
+ :patch: 0
4
+ :major: 0
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(orig)
75
- str = orig.downcase
76
- str.sub!(/^\w+:\/\//, '') # Strip protocol
77
- str = str.split('/').first if str.match(/\//) # Throw away anything after a slash
78
- str = str.split('.').last if str.match(/\./) # Take the last one of foo.bar.baz
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
- def test_find_tld_by_exact_match
6
+ should 'find TLD by exact match' do
6
7
  assert_equal 'au', TLD.find('au').tld
7
8
  end
8
9
 
9
- def test_find_tld_by_exact_match_with_dot
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
- def test_find_tld_with_case
14
+ should 'find TLD with case' do
14
15
  assert_equal 'au', TLD.find('AU').tld
15
16
  end
16
17
 
17
- def test_find_tld_by_hostname
18
+ should 'find TLD by hostname' do
18
19
  assert_equal 'au', TLD.find('foo.bar.au').tld
19
20
  end
20
21
 
21
- def test_find_tld_by_url
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
- def test_get_tld_currency
26
+ should 'get TLD currency' do
26
27
  assert_equal 'AUD', TLD.find('au').currency
27
28
  end
28
29
 
29
- def test_get_mapped_tld_currency
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
- def test_get_tld_name
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
- def test_get_iso_alpha3_code
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
- def test_com_should_map_to_empty_currency_not_comoros
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
- def test_unknown_tld
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.2.1"
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 = ["Alex Rabarts"]
9
- s.date = %q{2009-02-27}
10
- s.description = %q{Provides meta information for Internet Top Level Domains (TLDs) such as a descriptive name, associated currency code and the TLD category.}
11
- s.email = ["alexrabarts@gmail.com"]
12
- s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
13
- s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "lib/tld.rb", "lib/tld/alpha3.rb", "lib/tld/cc_tld.rb", "lib/tld/currency.rb", "lib/tld/generic_tld.rb", "lib/tld/infrastructure_tld.rb", "lib/tld/name.rb", "lib/tld/pseudo_tld.rb", "lib/tld/reserved_tld.rb", "lib/tld/retired_tld.rb", "lib/tld/sponsored_tld.rb", "lib/tld/tld.rb", "rakelib/cultivate.rake", "rakelib/tld.rake", "rakelib/tld.rb", "rakelib/tld.rb.erb", "test/test_tld.rb", "tld.gemspec"]
14
- s.has_rdoc = true
15
- s.rdoc_options = ["--main", "README.txt"]
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.rubyforge_project = %q{tld}
18
- s.rubygems_version = %q{1.3.1}
19
- s.summary = %q{Provides meta information for Internet Top Level Domains (TLDs) such as a descriptive name, associated currency code and the TLD category.}
20
- s.test_files = ["test/test_tld.rb"]
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 = 2
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.add_development_dependency(%q<hoe>, [">= 1.8.2"])
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<hoe>, [">= 1.8.2"])
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<hoe>, [">= 1.8.2"])
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.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
- - Alex Rabarts
7
+ - alex
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-27 00:00:00 -08:00
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: "0"
23
+ version: 0.2.1
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: hoe
27
- type: :development
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: 1.8.2
33
+ version: "0"
34
34
  version:
35
- description: Provides meta information for Internet Top Level Domains (TLDs) such as a descriptive name, associated currency code and the TLD category.
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
- - History.txt
44
- - Manifest.txt
45
- - README.txt
42
+ - README.rdoc
46
43
  files:
44
+ - .gitignore
47
45
  - History.txt
48
46
  - Manifest.txt
49
- - README.txt
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/test_tld.rb
66
+ - test/tld_test.rb
68
67
  - tld.gemspec
69
- has_rdoc: true
70
- homepage:
68
+ has_rdoc: false
69
+ homepage: http://github.com/alexrabarts/tld
71
70
  post_install_message:
72
71
  rdoc_options:
73
- - --main
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: tld
89
+ rubyforge_project:
92
90
  rubygems_version: 1.2.0
93
91
  signing_key:
94
- specification_version: 2
95
- summary: Provides meta information for Internet Top Level Domains (TLDs) such as a descriptive name, associated currency code and the TLD category.
92
+ specification_version: 3
93
+ summary: Provides meta information for Internet Top Level Domains (TLDs).
96
94
  test_files:
97
- - test/test_tld.rb
95
+ - test/tld_test.rb