uncharted 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +11 -0
- data/lib/uncharted/country.rb +26 -2
- data/lib/uncharted/territory.rb +19 -2
- data/lib/uncharted/version.rb +1 -1
- data/test/country_test.rb +15 -9
- metadata +14 -14
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
0.0.11 (2011-11-14)
|
2
|
+
-------------------
|
3
|
+
|
4
|
+
- Country.find_by_name and Territory.find_by_name
|
5
|
+
|
6
|
+
|
7
|
+
0.0.10 (2011-11-11)
|
8
|
+
-------------------
|
9
|
+
|
10
|
+
- Internationalization finally working (need to update translations though)
|
11
|
+
|
1
12
|
0.0.7 (2011-08-31)
|
2
13
|
------------------
|
3
14
|
|
data/lib/uncharted/country.rb
CHANGED
@@ -21,6 +21,10 @@ module Uncharted
|
|
21
21
|
I18n.t("countries.#{@alpha2}", {locale: options[:locale] || I18n.locale, default: @name})
|
22
22
|
end
|
23
23
|
|
24
|
+
def names
|
25
|
+
@names ||= Country.split_name(@name)
|
26
|
+
end
|
27
|
+
|
24
28
|
def to_s
|
25
29
|
@alpha2
|
26
30
|
end
|
@@ -35,10 +39,24 @@ module Uncharted
|
|
35
39
|
objects.collect {|c| data[c]}
|
36
40
|
when Country
|
37
41
|
objects
|
38
|
-
else
|
39
|
-
|
42
|
+
else # code
|
43
|
+
code = objects.to_s
|
44
|
+
code.upcase!
|
45
|
+
data[code]
|
40
46
|
end
|
41
47
|
end
|
48
|
+
|
49
|
+
def self.find_by_name(name)
|
50
|
+
closest = [nil, 0]
|
51
|
+
@data.each do |code, country|
|
52
|
+
return country if country.name == name
|
53
|
+
intersection = country.names & Country.split_name(name)
|
54
|
+
size = intersection.size
|
55
|
+
return country if size == country.names.size
|
56
|
+
closest = [country, size] if closest.last < size
|
57
|
+
end
|
58
|
+
return closest.first
|
59
|
+
end
|
42
60
|
|
43
61
|
def self.countries
|
44
62
|
@data.values
|
@@ -47,6 +65,12 @@ module Uncharted
|
|
47
65
|
def self.data
|
48
66
|
@data ||= {}
|
49
67
|
end
|
68
|
+
|
69
|
+
def self.split_name(name)
|
70
|
+
name = I18n.transliterate(name)
|
71
|
+
name.downcase!
|
72
|
+
name.split
|
73
|
+
end
|
50
74
|
|
51
75
|
end
|
52
76
|
|
data/lib/uncharted/territory.rb
CHANGED
@@ -47,18 +47,35 @@ module Uncharted
|
|
47
47
|
I18n.t("territories.#{@country_code}#{@abbr}", {locale: options[:locale] || I18n.locale}, default: @name)
|
48
48
|
end
|
49
49
|
|
50
|
+
def names
|
51
|
+
@names ||= Country.split_name(@name)
|
52
|
+
end
|
53
|
+
|
50
54
|
def to_s
|
51
55
|
@abbr
|
52
56
|
end
|
53
57
|
|
54
58
|
def self.find(object)
|
55
|
-
object.is_a?(Territory) ? object : data[object]
|
59
|
+
territory = object.is_a?(Territory) ? object : data[object]
|
56
60
|
end
|
57
|
-
|
61
|
+
|
58
62
|
def self.data
|
59
63
|
@data ||= {}
|
60
64
|
end
|
61
65
|
|
66
|
+
def self.find_by_name(name)
|
67
|
+
closest = [nil, 0]
|
68
|
+
@data.each do |code, territory|
|
69
|
+
return territory if territory.name == name
|
70
|
+
intersection = territory.names & Country.split_name(name)
|
71
|
+
size = intersection.size
|
72
|
+
return territory if size == territory.names.size
|
73
|
+
closest = [territory, size] if closest.last < size
|
74
|
+
end
|
75
|
+
return closest.first
|
76
|
+
end
|
77
|
+
|
78
|
+
|
62
79
|
end
|
63
80
|
|
64
81
|
end
|
data/lib/uncharted/version.rb
CHANGED
data/test/country_test.rb
CHANGED
@@ -24,22 +24,19 @@ class TestCountry < MiniTest::Unit::TestCase
|
|
24
24
|
def test_to_s
|
25
25
|
assert_equal 'BR', @br.to_s
|
26
26
|
end
|
27
|
-
|
28
|
-
def test_country_count
|
29
|
-
assert_equal 247, Country.count
|
30
|
-
assert_equal 27, Country.subdivisions.values.count
|
31
|
-
end
|
32
27
|
|
33
28
|
def test_territories
|
34
29
|
df = Territory.find('BR-DF')
|
30
|
+
assert_equal @br, df.country
|
35
31
|
assert_equal [df], @br.districts
|
36
32
|
assert_equal 26, @br.states.count
|
37
33
|
assert_equal 27, @br.subdivisions.count
|
38
34
|
assert @br.territories.empty?
|
39
35
|
|
40
|
-
|
41
|
-
assert_equal '
|
42
|
-
assert_equal 'PR',
|
36
|
+
pr = Territory.find('BR-PR')
|
37
|
+
assert_equal 'Paraná', pr.name
|
38
|
+
assert_equal 'PR', pr.abbr
|
39
|
+
assert_equal 'PR', pr.to_s
|
43
40
|
end
|
44
41
|
|
45
42
|
def test_classes
|
@@ -53,11 +50,20 @@ class TestCountry < MiniTest::Unit::TestCase
|
|
53
50
|
|
54
51
|
def test_translation
|
55
52
|
assert_equal "Brazil", @br.name(locale: :en)
|
56
|
-
assert_equal "Brasil", @br.name(locale: 'pt-BR')
|
53
|
+
assert_equal "Brasil", @br.name(locale: :'pt-BR')
|
57
54
|
end
|
58
55
|
|
59
56
|
def test_inspection
|
60
57
|
assert_equal "BR: 'Brazil'", @br.inspect
|
61
58
|
end
|
59
|
+
|
60
|
+
def test_find_by_name
|
61
|
+
assert_equal Country.find('US'), Country.find_by_name('States United')
|
62
|
+
assert_equal Country.find('GB'), Country.find_by_name('Kingdom')
|
63
|
+
assert_equal Country.find('FR'), Country.find_by_name('France')
|
64
|
+
assert_equal Territory.find('BR-PR'), Territory.find_by_name('Paraná')
|
65
|
+
assert_equal Territory.find('BR-RN'), Territory.find_by_name('Rio Grande do Norte')
|
66
|
+
assert_equal Territory.find('BR-RS'), Territory.find_by_name('R Grande do Sul')
|
67
|
+
end
|
62
68
|
|
63
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uncharted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
16
|
-
requirement: &
|
16
|
+
requirement: &2160752460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2160752460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: minitest
|
27
|
-
requirement: &
|
27
|
+
requirement: &2160751920 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2160751920
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: purdytest
|
38
|
-
requirement: &
|
38
|
+
requirement: &2160751300 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2160751300
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: simplecov
|
49
|
-
requirement: &
|
49
|
+
requirement: &2160750860 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2160750860
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov-rcov
|
60
|
-
requirement: &
|
60
|
+
requirement: &2160750380 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2160750380
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yard
|
71
|
-
requirement: &
|
71
|
+
requirement: &2160749660 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2160749660
|
80
80
|
description: Provide ISO 3166 codes and english name for countries and their political
|
81
81
|
divisions
|
82
82
|
email:
|