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 +4 -4
- data/History.txt +4 -0
- data/README.rdoc +10 -8
- data/VERSION +1 -1
- data/lib/iso_country_codes/iso_country_codes.rb +11 -0
- data/test/iso_country_codes_test.rb +24 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdaa725630fdd0526188835414249347dfb27d03
|
4
|
+
data.tar.gz: c2bdf6f01db237598b2ecc19b95bf15ca8f84fc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64110f1ed3ef27269d5b6b70d2b675d02824c3e73cab8ab795a24c73c4ce0d0f565333f2fb6a91ddd25a14e0bcdd23b7209092946aaf37ff26a5845a8df05bd7
|
7
|
+
data.tar.gz: 9c8b10d9fb339a331a382712dea6c4d9816f2219a5fdc06ffc2aa634e387d780781e7c2eedb1d7a5fbe144cfcd84e1c3b648864d166014f929d56a37809bf4a8
|
data/History.txt
CHANGED
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('
|
17
|
-
code.name # => "
|
18
|
-
code.numeric # => "
|
19
|
-
code.alpha2 # => "
|
20
|
-
code.alpha3 # => "
|
21
|
-
code.calling # => "+
|
22
|
-
code.continent # => "
|
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
|
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.
|
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
|