normalize_country 0.0.1

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.
@@ -0,0 +1,48 @@
1
+ require "minitest/autorun"
2
+ require "normalize_country"
3
+
4
+ describe NormalizeCountry do
5
+ it "normalizes to a country's ISO name by default" do
6
+ NormalizeCountry.convert("USA").must_equal("United States")
7
+ end
8
+
9
+ it "is case insensitive" do
10
+ NormalizeCountry.convert("usa").must_equal("United States")
11
+ NormalizeCountry.convert("UsA").must_equal("United States")
12
+ end
13
+
14
+ it "ignores extra spaces" do
15
+ NormalizeCountry.convert(" United States of America ").must_equal("United States")
16
+ end
17
+
18
+ it "normalizes a country's aliases" do
19
+ %w[America U.S. U.S.A.].each { |v| NormalizeCountry.convert(v).must_equal("United States") }
20
+ end
21
+
22
+ {:alpha2 => "US", :alpha3 => "USA", :ioc => "USA", :iso_name => "United States", :official => "United States of America", :fifa => "USA"}.each do |spec, expect|
23
+ it "normalizes to #{spec}" do
24
+ NormalizeCountry.convert("America", :to => spec).must_equal(expect)
25
+ end
26
+ end
27
+
28
+ it "returns nil if the normalization target is unknown" do
29
+ NormalizeCountry.convert("USA", :to => :wtf).must_be_nil
30
+ end
31
+
32
+ it "has a function form" do
33
+ NormalizeCountry("USA", :to => :ioc).must_equal("USA")
34
+ end
35
+
36
+ describe "when a default is set" do
37
+ before { NormalizeCountry.to = :alpha2 }
38
+ after { NormalizeCountry.to = :iso_name }
39
+
40
+ it "normalizes to the default when no target is given" do
41
+ NormalizeCountry.convert("United States").must_equal("US")
42
+ end
43
+
44
+ it "normalizes to the target when one is given" do
45
+ NormalizeCountry.convert("United States", :to => :alpha3).must_equal("USA")
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,47 @@
1
+ require "minitest/autorun"
2
+ require "tempfile"
3
+ require "yaml"
4
+
5
+ temp = Tempfile.new "normalize_country"
6
+ targets = %w[alpha2 alpha3 ioc iso_name official fifa short]
7
+ data = Hash[*targets*2]
8
+ data["aliases"] = ["the first alias", "2nd alias"]
9
+ temp.puts(YAML.dump("US" => data))
10
+ ENV["NORMALIZE_COUNTRY_DATAFILE"] = temp.path
11
+
12
+ require "normalize_country"
13
+
14
+ describe NormalizeCountry do
15
+ it "normalizes to a country's ISO name by default" do
16
+ NormalizeCountry.normalize("alpha2").must_equal("iso_name")
17
+ end
18
+
19
+ it "is case insensitive" do
20
+ NormalizeCountry.normalize("ALPHA2").must_equal("iso_name")
21
+ NormalizeCountry.normalize("alpha2").must_equal("iso_name")
22
+ end
23
+
24
+ it "ignores extra spaces" do
25
+ NormalizeCountry.normalize(" the first alias ").must_equal("iso_name")
26
+ end
27
+
28
+ %w[alpha2 alpha3 ioc iso_name official fifa short].each do |spec|
29
+ it "normalizes to #{spec}" do
30
+ NormalizeCountry.normalize("2nd alias", :to => spec).must_equal(spec)
31
+ NormalizeCountry.normalize("the first alias", :to => spec).must_equal(spec)
32
+ end
33
+ end
34
+
35
+ context "when a default to value is set" do
36
+ before { NormalizeCountry.to = :alpha2 }
37
+ after { NormalizeCountry.to = :iso_name }
38
+
39
+ it "normalizes to the default when no target is given" do
40
+ NormalizeCountry.normalize("iso_name").must_equal("alpha2")
41
+ end
42
+
43
+ it "normalizes to the target when one is given" do
44
+ NormalizeCountry.normalize("iso_name", :to => :short).must_equal("short")
45
+ end
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: normalize_country
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Skye Shaw
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-04-21 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 63
29
+ segments:
30
+ - 0
31
+ - 9
32
+ - 2
33
+ version: 0.9.2
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ description: " Converts country names and codes from standardized and non-standardized names and abbreviations to one of the following:\n ISO 3166-1 (code/name), FIFA, IOC, a country's official name or shortened name.\n"
51
+ email: skye.shaw@gmail.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files:
57
+ - README.rdoc
58
+ files:
59
+ - lib/normalize_country.rb
60
+ - lib/normalize_country/countries/en.yml
61
+ - spec/normalize_country_spec.rb
62
+ - spec/normalize_country_spec.rb.x
63
+ - README.rdoc
64
+ homepage: http://github.com/sshaw/normalize_country
65
+ licenses:
66
+ - MIT
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.10
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Convert country names and codes to a standard
97
+ test_files:
98
+ - spec/normalize_country_spec.rb
99
+ - spec/normalize_country_spec.rb.x