iso_country_codes 0.7.7 → 0.7.8

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: 9a57d57e0f1e172cf16443c548c96321b05a4fc5
4
- data.tar.gz: 6d71a4bdc9fc06940a053432ff01d276e81c8071
3
+ metadata.gz: e3407315feef40a75fcfc9513b41b094aedbe17b
4
+ data.tar.gz: 0b53033413873611069018b59cc3fcb36f72cd20
5
5
  SHA512:
6
- metadata.gz: 6bab4f20d2b0b179d480cc671a7eec18e7cc8354e96a5e2ff07b9fc6a68b9701333fbfda59a588a7f1cfd814a1b981497dfc5ce2dcab0c069d36cf4c49e42b11
7
- data.tar.gz: 3f400ffeb54f50c1625c6626fcf1bb960a2949e942141bfd7fbaf800494fff4bdf3a796966da7314b02912471f128c8ef55226b84e75a8d6054f1be1dc91e4db
6
+ metadata.gz: b39f3664b3ca8aad85dae6bb60838139fe5b6fb20ea483f7e5f86e704c652a1a352b244889a3b523a8513b4fa6a90de7ae01f9a7da77f06f1078e1c3be19aefe
7
+ data.tar.gz: 43fae37741f6c235335cc4cb4b7ca9c4f96c5de5acef5ac753f7283fa54162f2412bcd85af8dff9d3cc46d0cd69150b77fc6bc0f943a1157927a498da62f35ca
@@ -1,3 +1,7 @@
1
+ ## 0.7.8
2
+
3
+ * Add (internal) override mechanism, and call TWN "Taiwan". (see #44)
4
+
1
5
  ## 0.7.7
2
6
 
3
7
  * Updated the main currency for Lithuania from `LTL` to `EUR` (see #43)
data/Gemfile CHANGED
@@ -6,5 +6,5 @@ gem 'rdoc'
6
6
  group :development, :test do
7
7
  gem 'nokogiri'
8
8
  gem 'erubis'
9
- gem "test-unit", "~> 3.0"
9
+ gem 'test-unit', '~> 3.0'
10
10
  end
@@ -43,6 +43,20 @@ Provides ISO codes, names and currencies for countries.
43
43
 
44
44
  gem install iso_country_codes
45
45
 
46
+ == DATA SOURCE:
47
+
48
+ IsoCountryCodes pulls its data from the Wikipedia ISO 3166-1 tables
49
+ (https://en.wikipedia.org/wiki/ISO_3166-1), combined with a small number of
50
+ overrides contained in the `overrides.yml` file. For example, the country name
51
+ of TWN is overridden to "Taiwan" from "Taiwan, Province of China", to make it
52
+ less politicised.
53
+
54
+ The format of the `overrides.yml` file is the 3-letter alpha country
55
+ code as the key, and the fields one wants to override as follows:
56
+
57
+ "TWN":
58
+ :name: "Taiwan"
59
+
46
60
  == LICENSE:
47
61
 
48
62
  (The MIT License)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.7
1
+ 0.7.8
@@ -1306,7 +1306,7 @@ class IsoCountryCodes
1306
1306
  end
1307
1307
  class TWN < Code #:nodoc:
1308
1308
  self.numeric = %q{158}
1309
- self.name = %q{Taiwan, Province of China}
1309
+ self.name = %q{Taiwan}
1310
1310
  self.alpha2 = %q{TW}
1311
1311
  self.alpha3 = %q{TWN}
1312
1312
  end
@@ -0,0 +1,3 @@
1
+ ---
2
+ "TWN":
3
+ :name: "Taiwan"
@@ -1,6 +1,7 @@
1
1
  require 'nokogiri'
2
2
  require 'open-uri'
3
3
  require 'erubis'
4
+ require 'yaml'
4
5
 
5
6
  class IsoCountryCodes
6
7
  module Task
@@ -30,6 +31,14 @@ class IsoCountryCodes
30
31
 
31
32
  next if value == ''
32
33
 
34
+ # This is a terrible hack to skip the first table of the
35
+ # Wikipedia page, under "Naming and disputes". The
36
+ # giveaway is that this table doesn't include a "Numeric
37
+ # code" field.
38
+ if key == :numeric
39
+ next unless value.to_i > 0
40
+ end
41
+
33
42
  value_hash[key] = value
34
43
 
35
44
  if value_hash.length == code_labels.length - 1
@@ -40,6 +49,8 @@ class IsoCountryCodes
40
49
  end
41
50
  end
42
51
 
52
+ codes = recurse_merge(codes, self.exceptions)
53
+
43
54
  to_ruby(codes) if codes
44
55
  end
45
56
 
@@ -48,6 +59,16 @@ class IsoCountryCodes
48
59
  eruby = Erubis::Eruby.new(tmpl)
49
60
  eruby.result(:codes => codes)
50
61
  end
62
+
63
+ def self.exceptions
64
+ @config ||= YAML.load_file('overrides.yml')
65
+ end
66
+
67
+ def self.recurse_merge(a,b)
68
+ a.merge(b) do |_,x,y|
69
+ (x.is_a?(Hash) && y.is_a?(Hash)) ? recurse_merge(x,y) : y
70
+ end
71
+ end
51
72
  end # UpdateCodes
52
73
  end # Task
53
74
  end # IsoCountryCodes
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.7
4
+ version: 0.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rabarts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-04 00:00:00.000000000 Z
11
+ date: 2017-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,6 +91,7 @@ files:
91
91
  - lib/iso_country_codes/iso_3166_1.rb
92
92
  - lib/iso_country_codes/iso_4217.rb
93
93
  - lib/iso_country_codes/iso_country_codes.rb
94
+ - overrides.yml
94
95
  - rakelib/cultivate.rake
95
96
  - rakelib/iso_3166_1.rake
96
97
  - rakelib/iso_3166_1.rb
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  version: '0'
118
119
  requirements: []
119
120
  rubyforge_project:
120
- rubygems_version: 2.5.1
121
+ rubygems_version: 2.6.11
121
122
  signing_key:
122
123
  specification_version: 4
123
124
  summary: Provides ISO 3166-1 country codes/names and ISO 4217 currencies.