countries 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/countries.gemspec +2 -2
- data/lib/countries/country.rb +7 -1
- data/spec/country_spec.rb +36 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.1
|
data/countries.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{countries}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{hexorx}]
|
12
|
-
s.date = %q{2011-09-
|
12
|
+
s.date = %q{2011-09-16}
|
13
13
|
s.description = %q{All sorts of useful information about every country packaged as pretty little country objects. It includes data from ISO 3166 (countries and subdivisions), ISO 4217 (currency), and E.164 (phone numbers). As a bonus it even adds a country_select helper to rails projects.}
|
14
14
|
s.email = %q{hexorx@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/countries/country.rb
CHANGED
@@ -70,9 +70,15 @@ class ISO3166::Country
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def find_by_name(name)
|
73
|
+
name.downcase!
|
73
74
|
Data.select do |k,v|
|
74
|
-
v["name"] == name || v["names"].include?(name)
|
75
|
+
v["name"].downcase == name || v["names"].map{ |n| n.downcase }.include?(name)
|
75
76
|
end.first
|
76
77
|
end
|
78
|
+
|
79
|
+
def find_country_by_name(name)
|
80
|
+
result = self.find_by_name(name)
|
81
|
+
result ? self.new(result.first) : nil
|
82
|
+
end
|
77
83
|
end
|
78
84
|
end
|
data/spec/country_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
4
|
|
3
5
|
describe ISO3166::Country do
|
@@ -160,6 +162,12 @@ describe ISO3166::Country do
|
|
160
162
|
its(:first) { should == "PL" }
|
161
163
|
end
|
162
164
|
|
165
|
+
context "when search lowercase name in 'name'" do
|
166
|
+
subject { ISO3166::Country.find_by_name("poland") }
|
167
|
+
|
168
|
+
its(:first) { should == "PL" }
|
169
|
+
end
|
170
|
+
|
163
171
|
context "when search name in 'names'" do
|
164
172
|
subject { ISO3166::Country.find_by_name("Polonia") }
|
165
173
|
|
@@ -167,6 +175,34 @@ describe ISO3166::Country do
|
|
167
175
|
end
|
168
176
|
end
|
169
177
|
|
178
|
+
describe ".find_country_by_name" do
|
179
|
+
context "when search name found" do
|
180
|
+
let(:uk) { ISO3166::Country.find_country_by_name("United Kingdom") }
|
181
|
+
|
182
|
+
it "should be a country instance" do
|
183
|
+
uk.should be_a(ISO3166::Country)
|
184
|
+
uk.alpha2.should == "GB"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context "when search lowercase name found" do
|
189
|
+
let(:uk) { ISO3166::Country.find_country_by_name("united kingdom") }
|
190
|
+
|
191
|
+
it "should be a country instance" do
|
192
|
+
uk.should be_a(ISO3166::Country)
|
193
|
+
uk.alpha2.should == "GB"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context "when search name not found" do
|
198
|
+
let(:bogus) { ISO3166::Country.find_country_by_name("Does not exist") }
|
199
|
+
|
200
|
+
it "should be a country instance" do
|
201
|
+
bogus.should == nil
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
170
206
|
describe "names in Data" do
|
171
207
|
it "should be unique (to allow .find_by_name work properly)" do
|
172
208
|
names = ISO3166::Country::Data.collect do |k,v|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: countries
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 1
|
10
|
+
version: 0.6.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- hexorx
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-16 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|