iso_country_codes 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41bee119bf0ac1ab5496544b3d62c2bf9cbcab06
4
- data.tar.gz: c649cd0acdf92729d3e3e2a7b39e5bcad53fd3dc
3
+ metadata.gz: cdaa725630fdd0526188835414249347dfb27d03
4
+ data.tar.gz: c2bdf6f01db237598b2ecc19b95bf15ca8f84fc8
5
5
  SHA512:
6
- metadata.gz: 92c6b6fdf850a365c90bf1ff77d8937e1a48570ca8e86de41aa26c38d45a2569be169c49d772df468f51baa423e8e7f875073c73520afd8d9a42d2e1e1ba0f91
7
- data.tar.gz: 130ace694034cbac7a9591f9b55ed54d932d52f1b97ee7d7d9955008788ad8be0093d3b3fe8ec5d430ccf7b8480ff5cb1bc811939f80fb6a1138563b6428cbc0
6
+ metadata.gz: 64110f1ed3ef27269d5b6b70d2b675d02824c3e73cab8ab795a24c73c4ce0d0f565333f2fb6a91ddd25a14e0bcdd23b7209092946aaf37ff26a5845a8df05bd7
7
+ data.tar.gz: 9c8b10d9fb339a331a382712dea6c4d9816f2219a5fdc06ffc2aa634e387d780781e7c2eedb1d7a5fbe144cfcd84e1c3b648864d166014f929d56a37809bf4a8
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.7.1 / 2015-05-21
2
+
3
+ * Adds IsoCountryCodes.search_by_iban method to search by IBAN code
4
+
1
5
  === 0.7.0 / 2015-05-21
2
6
 
3
7
  * Adds ISO 13616-1 IBAN codes
data/README.rdoc CHANGED
@@ -13,23 +13,25 @@ Provides ISO codes, names and currencies for countries.
13
13
  == SYNOPSIS:
14
14
 
15
15
  # Finding an ISO code returns the country name and other code formats
16
- code = IsoCountryCodes.find('au')
17
- code.name # => "Australia"
18
- code.numeric # => "036"
19
- code.alpha2 # => "AU"
20
- code.alpha3 # => "AUS"
21
- code.calling # => "+61"
22
- code.continent # => "OC"
16
+ code = IsoCountryCodes.find('usa')
17
+ code.name # => "United Kingdom of Great Britain and Northern Ireland"
18
+ code.numeric # => "826"
19
+ code.alpha2 # => "GB"
20
+ code.alpha3 # => "GBR"
21
+ code.calling # => "+44"
22
+ code.continent # => "EU"
23
+ code.iban # => "GB"
23
24
 
24
25
  # Codes can be found via numeric, alpha-2 or alpha-3 format
25
26
  IsoCountryCodes.find(36)
26
27
  IsoCountryCodes.find('au')
27
28
  IsoCountryCodes.find('aus')
28
29
 
29
- # Codes can also be returned by searching country name, currency or calling/dialing code
30
+ # Codes can also be returned by searching country name, currency, calling/dialing code or IBAN
30
31
  IsoCountryCodes.search_by_name('australia')
31
32
  IsoCountryCodes.search_by_currency('aud')
32
33
  IsoCountryCodes.search_by_calling_code('+61')
34
+ IsoCountryCodes.search_by_iban('gb')
33
35
 
34
36
  # Fetch a country's local currency
35
37
  IsoCountryCodes.find('aus').currency # => "AUD"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.1
@@ -76,5 +76,16 @@ class IsoCountryCodes # :nodoc:
76
76
 
77
77
  instances
78
78
  end
79
+
80
+ def search_by_iban(code, &fallback)
81
+ fallback ||= DEFAULT_FALLBACK
82
+
83
+ code = code.to_str.upcase
84
+ instances = all.select { |c| c.iban == code }
85
+
86
+ return fallback.call "No ISO 3166-1 codes could be found searching with IBAN '#{code}'." if instances.empty?
87
+
88
+ instances
89
+ end
79
90
  end
80
91
  end
@@ -164,6 +164,30 @@ class TestIsoCountryCodes < Test::Unit::TestCase
164
164
  assert_equal IsoCountryCodes.search_by_calling_code('00') {[]}, []
165
165
  end
166
166
 
167
+ def test_search_by_iban_lowercase
168
+ assert_equal [IsoCountryCodes::Code::GBR.instance], IsoCountryCodes.search_by_iban('gb')
169
+ end
170
+
171
+ def test_search_by_iban_uppercase
172
+ assert_equal [IsoCountryCodes::Code::GBR.instance], IsoCountryCodes.search_by_iban('GB')
173
+ end
174
+
175
+ def test_search_by_iban_invalid_value_and_raise_exception
176
+ assert_raise IsoCountryCodes::UnknownCodeError do
177
+ IsoCountryCodes.search_by_iban('xx')
178
+ end
179
+ end
180
+
181
+ def test_search_by_iban_invalid_value_and_raise_custom_exception
182
+ assert_raise ArgumentError do
183
+ IsoCountryCodes.search_by_iban('xx'){ |error| raise ArgumentError }
184
+ end
185
+ end
186
+
187
+ def test_search_by_iban_invalid_value_and_return_custom_value
188
+ assert_equal IsoCountryCodes.search_by_iban('xx') {[]}, []
189
+ end
190
+
167
191
  def test_get_main_currency
168
192
  assert_equal 'AUD', IsoCountryCodes.find('AUS').main_currency
169
193
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iso_country_codes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rabarts