normalize_country 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,8 @@ require "minitest/autorun"
2
2
  require "normalize_country"
3
3
 
4
4
  describe NormalizeCountry do
5
+ COUNTRY_COUNT = 247
6
+
5
7
  it "normalizes to a country's ISO name by default" do
6
8
  NormalizeCountry.convert("USA").must_equal("United States")
7
9
  end
@@ -19,12 +21,12 @@ describe NormalizeCountry do
19
21
  %w[America U.S. U.S.A.].each { |v| NormalizeCountry.convert(v).must_equal("United States") }
20
22
  end
21
23
 
22
- {:alpha2 => "US", :alpha3 => "USA", :ioc => "USA", :iso_name => "United States", :official => "United States of America", :fifa => "USA"}.each do |spec, expect|
24
+ {:alpha2 => "US", :alpha3 => "USA", :ioc => "USA", :iso_name => "United States", :numeric => "840", :official => "United States of America", :fifa => "USA"}.each do |spec, expect|
23
25
  it "normalizes to #{spec}" do
24
26
  NormalizeCountry.convert("America", :to => spec).must_equal(expect)
25
27
  end
26
28
  end
27
-
29
+
28
30
  it "returns nil if the normalization target is unknown" do
29
31
  NormalizeCountry.convert("USA", :to => :wtf).must_be_nil
30
32
  end
@@ -32,8 +34,92 @@ describe NormalizeCountry do
32
34
  it "has a function form" do
33
35
  NormalizeCountry("USA", :to => :ioc).must_equal("USA")
34
36
  end
35
-
36
- describe "when a default is set" do
37
+
38
+ describe ".to_h" do
39
+ before { NormalizeCountry.to = :numeric }
40
+ after { NormalizeCountry.to = :iso_name }
41
+
42
+ describe "without a :to option" do
43
+ it "uses the format option as the key and the default :to option as the value" do
44
+ hash = NormalizeCountry.to_h(:alpha3)
45
+ hash.must_be_instance_of Hash
46
+ hash["USA"].must_equal "840"
47
+ hash["GBR"].must_equal "826"
48
+ hash.size.must_equal COUNTRY_COUNT
49
+ end
50
+ end
51
+
52
+ describe "with a :to option" do
53
+ it "uses the format option as the key and the :to option as the value" do
54
+ hash = NormalizeCountry.to_h(:alpha3, :to => :alpha2)
55
+ hash.must_be_instance_of Hash
56
+ hash["USA"].must_equal "US"
57
+ hash["GBR"].must_equal "GB"
58
+ hash.size.must_equal COUNTRY_COUNT
59
+ end
60
+ end
61
+
62
+ describe "with an unknown format argument" do
63
+ it "returns an empty Hash" do
64
+ hash = NormalizeCountry.to_h(:wtf)
65
+ hash.must_be_instance_of Hash
66
+ hash.must_be_empty
67
+
68
+ hash = NormalizeCountry.to_h(:alpha2, :to => :wtf)
69
+ hash.must_be_instance_of Hash
70
+ hash.must_be_empty
71
+ end
72
+ end
73
+ end
74
+
75
+ describe ".to_a" do
76
+ describe "without a format argument" do
77
+ before { NormalizeCountry.to = :numeric }
78
+ after { NormalizeCountry.to = :iso_name }
79
+
80
+ it "returns an Array of countries in the default format" do
81
+ list = NormalizeCountry.to_a
82
+ list.must_be_instance_of Array
83
+ list.must_include "840" # US
84
+ list.must_include "826" # GB
85
+ list.size.must_equal COUNTRY_COUNT
86
+ end
87
+ end
88
+
89
+ describe "with a format argument" do
90
+ it "returns an Array of countries in the given format" do
91
+ list = NormalizeCountry.to_a(:alpha3)
92
+ list.must_be_instance_of Array
93
+ list.must_include "USA"
94
+ list.must_include "GBR"
95
+ list.size.must_equal COUNTRY_COUNT
96
+ end
97
+ end
98
+
99
+ describe "with an unknown format argument" do
100
+ it "returns an empty Array" do
101
+ list = NormalizeCountry.to_a(:wtf)
102
+ list.must_be_instance_of Array
103
+ list.must_be_empty
104
+ end
105
+ end
106
+ end
107
+
108
+ describe ".formats" do
109
+ it "returns a list of supported formats" do
110
+ expected = [:alpha2, :alpha3, :fifa, :ioc, :iso_name, :numeric, :official, :short, :simple]
111
+ formats = NormalizeCountry.formats
112
+
113
+ # Ugh, support this in 1.8.7 for a least one version
114
+ if Symbol < Comparable
115
+ formats.sort.must_equal(expected.sort)
116
+ else
117
+ formats.sort_by { |f| f.to_s }.must_equal(expected.sort_by { |f| f.to_s })
118
+ end
119
+ end
120
+ end
121
+
122
+ describe "when a default is set" do
37
123
  before { NormalizeCountry.to = :alpha2 }
38
124
  after { NormalizeCountry.to = :iso_name }
39
125
 
metadata CHANGED
@@ -1,99 +1,83 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
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
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Skye Shaw
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2013-04-21 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2013-11-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: rake
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
26
17
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 63
29
- segments:
30
- - 0
31
- - 9
32
- - 2
33
- version: 0.9.2
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
34
20
  type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: minitest
38
21
  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"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
48
34
  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"
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ! " Converts country names and codes from standardized and non-standardized
42
+ names and abbreviations to one of the following:\n ISO 3166-1 (code/name/number),
43
+ FIFA, IOC, a country's official name or shortened name.\n\n Includes a small
44
+ script to convert names/codes in a DB, XML or CSV file.\n"
51
45
  email: skye.shaw@gmail.com
52
- executables: []
53
-
46
+ executables:
47
+ - normalize_country
54
48
  extensions: []
55
-
56
- extra_rdoc_files:
49
+ extra_rdoc_files:
57
50
  - README.rdoc
58
- files:
51
+ files:
59
52
  - lib/normalize_country.rb
60
53
  - lib/normalize_country/countries/en.yml
61
54
  - spec/normalize_country_spec.rb
62
- - spec/normalize_country_spec.rb.x
63
55
  - README.rdoc
56
+ - bin/normalize_country
64
57
  homepage: http://github.com/sshaw/normalize_country
65
- licenses:
58
+ licenses:
66
59
  - MIT
60
+ metadata: {}
67
61
  post_install_message:
68
62
  rdoc_options: []
69
-
70
- require_paths:
63
+ require_paths:
71
64
  - 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"
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
90
75
  requirements: []
91
-
92
76
  rubyforge_project:
93
- rubygems_version: 1.8.10
77
+ rubygems_version: 2.0.7
94
78
  signing_key:
95
- specification_version: 3
79
+ specification_version: 4
96
80
  summary: Convert country names and codes to a standard
97
- test_files:
81
+ test_files:
98
82
  - spec/normalize_country_spec.rb
99
- - spec/normalize_country_spec.rb.x
83
+ has_rdoc:
@@ -1,47 +0,0 @@
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