itu_codes 0.4.1 → 0.4.2

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.
data/README.md CHANGED
@@ -49,24 +49,32 @@ Country code lookup based on official ISO-3166-1 specifications:
49
49
  ItuCodes.compatriots? '1984', '1985'
50
50
  # => true
51
51
 
52
- # =====================================================
53
- # = Using 2-letter ISO country codes is most reliable =
54
- # =====================================================
55
52
  # ... and then there's the
56
53
  # North American 'situation' ...
57
54
  ItuCodes.compatriots? '1264', '1818'
58
55
  # => false
59
56
 
57
+ # =====================================================
58
+ # = Using 2-letter ISO country codes is most reliable =
59
+ # =====================================================
60
+
60
61
  # Convert from and to ISO 2-letter country codes:
61
62
  ItuCodes.iso2itu('US')
62
63
  # => "1"
63
64
 
65
+ # Convert from and to ISO 2-letter country codes:
66
+ ItuCodes.itu2iso('1')
67
+ # => ["AS", "AI", "AG", "BS", "BB", "BM", "VG", "CA", "KY", "DM", "DO", "GD", "GU", "JM", "MS", "MP", "PR", "KN", "LC", "VC", "SX", "TT", "TC", "US", "VI"]
68
+
64
69
  # Mexico
65
70
  # ISO 3361 code : MX
66
71
  # ITU code : 52
67
72
  ItuCodes.iso2itu('MX')
68
73
  # => "52"
69
74
 
75
+ ItuCodes.itu2iso('52')
76
+ # => "MX"
77
+
70
78
 
71
79
  [1]: http://www.itu.int/pub/T-SP-E.164D-11-2011
72
80
  [2]: http://www.itu.int/dms_pub/itu-t/opb/sp/T-SP-E.164D-11-2011-PDF-E.pdf
@@ -4,6 +4,7 @@ module ItuCodes
4
4
  module Helpers
5
5
  ISO2ITU = YAML.load_file( File.expand_path(File.dirname(__FILE__)) + '/../data/iso_code_to_itu_country_names.yml')
6
6
 
7
+ # country name is the one used by ITU, not ISO
7
8
  def self.country_code_lookup(country_name)
8
9
  ISO2ITU.key(country_name)
9
10
  end
@@ -1,3 +1,3 @@
1
1
  module ItuCodes
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
data/lib/itu_codes.rb CHANGED
@@ -41,6 +41,18 @@ module ItuCodes
41
41
  find_by_name(country_name)
42
42
  end
43
43
 
44
+ def itu2iso(itu)
45
+ name = find_by_itu_code(itu)
46
+
47
+ if name.is_a?(String)
48
+ Helpers.country_code_lookup(name)
49
+ elsif name.is_a?(Array)
50
+ name.map do |s|
51
+ Helpers.country_code_lookup(s)
52
+ end
53
+ end
54
+ end
55
+
44
56
  # returns true for any valid ITU code
45
57
  # valid_code?(1) => true
46
58
  # valid_code?(1818) => false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itu_codes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: