iso_country_codes 0.7.4 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bceead1622c275bdc8e39e5f7dd676a8f3f51214
4
- data.tar.gz: 25940d7dc70dae061934fce6152521d95234a02a
3
+ metadata.gz: 8bcbc624cb853a459884e1d83c6e348f96a481f6
4
+ data.tar.gz: cf8c1e261462ef9f0c91071b988c72ad7f658173
5
5
  SHA512:
6
- metadata.gz: 84146dc600c4ceb76df414ccb26ee2daeaa3a8bff563bb7c9d652d0744ed3b46afe8869de755c8d0589cbab6483833c540fc8791bcbae861a9a0bfa4f2a56cc7
7
- data.tar.gz: f90fd6cfdf3a96874592a72bccba90511ed86e5b6b9e324f056aeee122883243b23a2aadfd66f5b8e92d6293455b629ee953eba124664bb4c239ae1af4a6dd94
6
+ metadata.gz: a4186a05e1c54e6020144837b22599c7a34b0cc8fc6cb872c82e96e9e32f5339c7017d6632cdf7c0164b57c264020fe51f93e6a29d6dd05b5467c5d8734fe4bb
7
+ data.tar.gz: 0f3cab4fe9ac280d55aedc1b4ae620047c4df1292fca5f2a5adba8af818099583b1b308dac86c3a4cc6fcd37f08231582e2e09c24aff70c083a25921c435a4d3
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  iso_country_codes-*.gem
2
+ .bundle/
data/.travis.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  language: ruby
2
2
  bundler_args: --without development
3
3
  rvm:
4
+ - 2.3.0
5
+ - 2.2.4
6
+ - 2.1
4
7
  - 2.0.0
5
8
  - 1.9.3
6
9
  - ruby-head
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.7.5
2
+
3
+ * Improved `search_by_name` to handle names with commas and parentheses (see #37)
4
+
1
5
  ## 0.7.4
2
6
 
3
7
  * Fixed calling code for Monaco
data/Gemfile CHANGED
@@ -3,7 +3,8 @@ source 'https://rubygems.org'
3
3
  gem 'rake'
4
4
  gem 'rdoc'
5
5
 
6
- group :development do
6
+ group :development, :test do
7
7
  gem 'nokogiri'
8
8
  gem 'erubis'
9
+ gem "test-unit", "~> 3.0"
9
10
  end
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.png" alt="Build Status" />}[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.4
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
@@ -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('http://en.wikipedia.org/wiki/ISO_3166-1'), nil, 'UTF-8')
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).text.strip
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
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-01-14 00:00:00.000000000 Z
11
+ date: 2016-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler