uncharted 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
1
1
  pt-BR:
2
2
  countries:
3
- AC: Ascenção
3
+ AC: Ascensão
4
4
  AD: Andorra
5
5
  AE: United Arab Emirates
6
- AF: Afghanistan
6
+ AF: Afeganistão
7
7
  AG: Antigua and Barbuda
8
8
  AI: Anguilla
9
9
  AL: Albania
@@ -231,7 +231,7 @@ pt-BR:
231
231
  UA: Ukraine
232
232
  UG: Uganda
233
233
  UM: Midway Islands
234
- US: United States
234
+ US: Estados Unidos
235
235
  UY: Uruguay
236
236
  UZ: Uzbekistan
237
237
  VA: Vatican City
@@ -37,7 +37,7 @@ module Uncharted
37
37
  case objects
38
38
  when Array
39
39
  objects.collect {|c| data[c]}
40
- when Country
40
+ when Country, nil
41
41
  objects
42
42
  else # code
43
43
  code = objects.to_s
@@ -47,6 +47,7 @@ module Uncharted
47
47
  end
48
48
 
49
49
  def self.find_by_name(name)
50
+ return nil if name.nil? || name == ""
50
51
  closest = [nil, 0]
51
52
  @data.each do |code, country|
52
53
  return country if country.name == name
@@ -57,6 +58,10 @@ module Uncharted
57
58
  end
58
59
  return closest.first
59
60
  end
61
+
62
+ def self.search(object)
63
+ find(object) || find_by_name(object)
64
+ end
60
65
 
61
66
  def self.countries
62
67
  @data.values
@@ -9,7 +9,8 @@ module Uncharted
9
9
  code && Country.find(code)
10
10
  end
11
11
 
12
- def serialize(country)
12
+ def serialize(object)
13
+ country = object.is_a?(Country) ? object : Country.search(object)
13
14
  country && country.code
14
15
  end
15
16
  end
@@ -21,7 +22,8 @@ module Uncharted
21
22
  code && Territory.find(code)
22
23
  end
23
24
 
24
- def serialize(territory)
25
+ def serialize(object)
26
+ territory = object.is_a?(Territory) ? object : Territory.search(object)
25
27
  territory && territory.code
26
28
  end
27
29
  end
@@ -56,7 +56,7 @@ module Uncharted
56
56
  end
57
57
 
58
58
  def self.find(object)
59
- territory = object.is_a?(Territory) ? object : data[object]
59
+ territory = object && object.is_a?(Territory) ? object : data[object]
60
60
  end
61
61
 
62
62
  def self.data
@@ -75,6 +75,10 @@ module Uncharted
75
75
  return closest.first
76
76
  end
77
77
 
78
+ def self.search(object)
79
+ find(object) || find_by_name(object)
80
+ end
81
+
78
82
 
79
83
  end
80
84
 
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Uncharted
3
- VERSION = '0.0.11'
3
+ VERSION = '0.0.12'
4
4
  end
data/test/country_test.rb CHANGED
@@ -65,5 +65,15 @@ class TestCountry < MiniTest::Unit::TestCase
65
65
  assert_equal Territory.find('BR-RN'), Territory.find_by_name('Rio Grande do Norte')
66
66
  assert_equal Territory.find('BR-RS'), Territory.find_by_name('R Grande do Sul')
67
67
  end
68
+
69
+ def test_search
70
+ assert_equal Country.find('US'), Country.search('States United')
71
+ assert_equal Country.find('US'), Country.search('US')
72
+ assert_equal Country.find('FR'), Country.search('France')
73
+ assert_equal Territory.find('BR-PR'), Territory.search('Paraná')
74
+ assert_equal Territory.find('BR-RN'), Territory.search('Rio Grande do Norte')
75
+ assert_equal Territory.find('BR-RS'), Territory.search('BR-RS')
76
+ assert_nil Territory.search('RS')
77
+ end
68
78
 
69
79
  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.11
4
+ version: 0.0.12
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-16 00:00:00.000000000 Z
12
+ date: 2011-11-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
16
- requirement: &2160752460 !ruby/object:Gem::Requirement
16
+ requirement: &2152785820 !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: *2160752460
24
+ version_requirements: *2152785820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: minitest
27
- requirement: &2160751920 !ruby/object:Gem::Requirement
27
+ requirement: &2152784260 !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: *2160751920
35
+ version_requirements: *2152784260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: purdytest
38
- requirement: &2160751300 !ruby/object:Gem::Requirement
38
+ requirement: &2152783100 !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: *2160751300
46
+ version_requirements: *2152783100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: simplecov
49
- requirement: &2160750860 !ruby/object:Gem::Requirement
49
+ requirement: &2152781840 !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: *2160750860
57
+ version_requirements: *2152781840
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov-rcov
60
- requirement: &2160750380 !ruby/object:Gem::Requirement
60
+ requirement: &2152780420 !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: *2160750380
68
+ version_requirements: *2152780420
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
- requirement: &2160749660 !ruby/object:Gem::Requirement
71
+ requirement: &2152779780 !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: *2160749660
79
+ version_requirements: *2152779780
80
80
  description: Provide ISO 3166 codes and english name for countries and their political
81
81
  divisions
82
82
  email: