iso_country_codes 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +7 -0
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/iso_country_codes/iso_3166_1.rb +6 -6
- data/lib/iso_country_codes/iso_country_codes.rb +6 -0
- data/rakelib/iso_3166_1.rb +4 -2
- data/test/iso_country_codes_test.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bcbc624cb853a459884e1d83c6e348f96a481f6
|
4
|
+
data.tar.gz: cf8c1e261462ef9f0c91071b988c72ad7f658173
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4186a05e1c54e6020144837b22599c7a34b0cc8fc6cb872c82e96e9e32f5339c7017d6632cdf7c0164b57c264020fe51f93e6a29d6dd05b5467c5d8734fe4bb
|
7
|
+
data.tar.gz: 0f3cab4fe9ac280d55aedc1b4ae620047c4df1292fca5f2a5adba8af818099583b1b308dac86c3a4cc6fcd37f08231582e2e09c24aff70c083a25921c435a4d3
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -6,9 +6,12 @@ GEM
|
|
6
6
|
mini_portile (0.6.2)
|
7
7
|
nokogiri (1.6.6.2)
|
8
8
|
mini_portile (~> 0.6.0)
|
9
|
+
power_assert (0.2.7)
|
9
10
|
rake (10.4.2)
|
10
11
|
rdoc (4.2.0)
|
11
12
|
json (~> 1.4)
|
13
|
+
test-unit (3.1.8)
|
14
|
+
power_assert
|
12
15
|
|
13
16
|
PLATFORMS
|
14
17
|
ruby
|
@@ -18,3 +21,7 @@ DEPENDENCIES
|
|
18
21
|
nokogiri
|
19
22
|
rake
|
20
23
|
rdoc
|
24
|
+
test-unit (~> 3.0)
|
25
|
+
|
26
|
+
BUNDLED WITH
|
27
|
+
1.11.2
|
data/README.rdoc
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
= iso_country_codes
|
2
|
-
{<img src="https://travis-ci.org/alexrabarts/iso_country_codes.
|
2
|
+
{<img src="https://travis-ci.org/alexrabarts/iso_country_codes.svg" alt="Build Status" />}[https://travis-ci.org/alexrabarts/iso_country_codes]
|
3
3
|
|
4
4
|
== DESCRIPTION:
|
5
5
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.5
|
@@ -224,6 +224,12 @@ class IsoCountryCodes
|
|
224
224
|
self.alpha2 = %q{BI}
|
225
225
|
self.alpha3 = %q{BDI}
|
226
226
|
end
|
227
|
+
class CPV < Code #:nodoc:
|
228
|
+
self.numeric = %q{132}
|
229
|
+
self.name = %q{Cabo Verde}
|
230
|
+
self.alpha2 = %q{CV}
|
231
|
+
self.alpha3 = %q{CPV}
|
232
|
+
end
|
227
233
|
class KHM < Code #:nodoc:
|
228
234
|
self.numeric = %q{116}
|
229
235
|
self.name = %q{Cambodia}
|
@@ -242,12 +248,6 @@ class IsoCountryCodes
|
|
242
248
|
self.alpha2 = %q{CA}
|
243
249
|
self.alpha3 = %q{CAN}
|
244
250
|
end
|
245
|
-
class CPV < Code #:nodoc:
|
246
|
-
self.numeric = %q{132}
|
247
|
-
self.name = %q{Cabo Verde}
|
248
|
-
self.alpha2 = %q{CV}
|
249
|
-
self.alpha3 = %q{CPV}
|
250
|
-
end
|
251
251
|
class CYM < Code #:nodoc:
|
252
252
|
self.numeric = %q{136}
|
253
253
|
self.name = %q{Cayman Islands}
|
@@ -41,6 +41,7 @@ class IsoCountryCodes # :nodoc:
|
|
41
41
|
instances = all.select { |c| c.name.to_s.upcase == str.to_s.upcase }
|
42
42
|
instances = all.select { |c| c.name.to_s.match(/^#{Regexp.escape(str)}/i) } if instances.empty?
|
43
43
|
instances = all.select { |c| c.name.to_s.match(/#{Regexp.escape(str)}/i) } if instances.empty?
|
44
|
+
instances = all.select { |c| word_set(c.name) == word_set(str) } if instances.empty?
|
44
45
|
|
45
46
|
return fallback.call "No ISO 3166-1 codes could be found searching with name '#{str}'." if instances.empty?
|
46
47
|
|
@@ -87,5 +88,10 @@ class IsoCountryCodes # :nodoc:
|
|
87
88
|
|
88
89
|
instances
|
89
90
|
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def word_set(str)
|
94
|
+
str.to_s.upcase.split(/\W/).reject(&:empty?).to_set
|
95
|
+
end
|
90
96
|
end
|
91
97
|
end
|
data/rakelib/iso_3166_1.rb
CHANGED
@@ -6,7 +6,7 @@ class IsoCountryCodes
|
|
6
6
|
module Task
|
7
7
|
module UpdateCodes
|
8
8
|
def self.get
|
9
|
-
doc = Nokogiri::HTML.parse(open('
|
9
|
+
doc = Nokogiri::HTML.parse(open('https://en.wikipedia.org/wiki/ISO_3166-1'), nil, 'UTF-8')
|
10
10
|
codes = {}
|
11
11
|
td_map = {
|
12
12
|
:name => 1,
|
@@ -24,7 +24,9 @@ class IsoCountryCodes
|
|
24
24
|
selector = "td:nth-of-type(#{td_map[key]})"
|
25
25
|
selector << ' a' if key == :name
|
26
26
|
|
27
|
-
value = row.search(selector).
|
27
|
+
value = row.search(selector).
|
28
|
+
reject { |el| el.parent.name == 'sup' }.
|
29
|
+
map(&:text).join.strip
|
28
30
|
|
29
31
|
next if value == ''
|
30
32
|
|
@@ -59,6 +59,14 @@ class TestIsoCountryCodes < Test::Unit::TestCase
|
|
59
59
|
assert_equal [IsoCountryCodes::Code::AUS.instance], IsoCountryCodes.search_by_name('Australia')
|
60
60
|
end
|
61
61
|
|
62
|
+
def test_search_comma_separated_name
|
63
|
+
assert_equal [IsoCountryCodes::Code::PSE.instance], IsoCountryCodes.search_by_name('State of Palestine')
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_search_parenthetical_name
|
67
|
+
assert_equal [IsoCountryCodes::Code::KOR.instance], IsoCountryCodes.search_by_name('Republic of Korea')
|
68
|
+
end
|
69
|
+
|
62
70
|
def test_search_by_name_returning_many_results_starting_wth_the_search_string
|
63
71
|
assert_equal([
|
64
72
|
IsoCountryCodes::Code::ARE.instance,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iso_country_codes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Rabarts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|