itu_codes 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +61 -0
- data/lib/itu_codes/constants.rb +750 -0
- data/lib/itu_codes/helpers.rb +13 -0
- data/lib/itu_codes/version.rb +1 -1
- data/lib/itu_codes.rb +106 -848
- metadata +61 -89
- data/README +0 -54
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# ItuCodes [![Build Status](https://secure.travis-ci.org/bowsersenior/itu_codes.png)](http://travis-ci.org/bowsersenior/itu_codes)
|
2
|
+
|
3
|
+
Helper library for telephone country codes based on the official International Telecommunications Union specifications:
|
4
|
+
|
5
|
+
* [LIST OF MOBILE COUNTRY OR GEOGRAPHICAL AREA CODES][1]
|
6
|
+
* [LIST OF ITU-T RECOMMENDATION E.164 ASSIGNED COUNTRY CODES (POSITION ON 1 NOVEMBER 2011)][2]
|
7
|
+
|
8
|
+
## Usage:
|
9
|
+
|
10
|
+
ItuCodes.valid_code? 8392813 # => false
|
11
|
+
|
12
|
+
ItuCodes.valid_code? 7 # => true
|
13
|
+
|
14
|
+
ItuCodes.parse_code 1818 # => 1
|
15
|
+
|
16
|
+
ItuCodes.parse_code 822 # => "82"
|
17
|
+
|
18
|
+
ItuCodes.parse_code 4 # => nil
|
19
|
+
|
20
|
+
ItuCodes.find("France") # => "33"
|
21
|
+
|
22
|
+
ItuCodes.find("995") # => "Georgia"
|
23
|
+
|
24
|
+
ItuCodes.find("Erewhon") # => nil
|
25
|
+
|
26
|
+
ItuCodes.find("123123995") # => nil
|
27
|
+
|
28
|
+
# Despite the same 1st digit,
|
29
|
+
# these are for different
|
30
|
+
# countries ...
|
31
|
+
ItuCodes.compatriots? 822, 811 # => false
|
32
|
+
|
33
|
+
# ... but these are for
|
34
|
+
# the same country ...
|
35
|
+
ItuCodes.compatriots? 122, 111 # => true
|
36
|
+
|
37
|
+
# =====================================================
|
38
|
+
# = Using 2-letter ISO country codes is most reliable =
|
39
|
+
# =====================================================
|
40
|
+
# ... and then there's the
|
41
|
+
# North American 'situation' ...
|
42
|
+
ItuCodes.compatriots? 1264, 1818 # => false
|
43
|
+
|
44
|
+
# Convert from and to ISO 2-letter country codes:
|
45
|
+
ItuCodes.iso2itu('US') # => "1"
|
46
|
+
|
47
|
+
ItuCodes.itu2iso('1')
|
48
|
+
# => ["US", "CA", "AS", "AI", "AG", "BS", "BB", "BM", "KY", "DM", "DO", "GD", "GU", "JM", "MS", "MP", "KN", "LC", "VC", "TT", "TC"]
|
49
|
+
|
50
|
+
# Mexico
|
51
|
+
# ISO 3361 code : MX
|
52
|
+
# ITU code : 52
|
53
|
+
ItuCodes.iso2itu('MX') # => "52"
|
54
|
+
|
55
|
+
# Georgia
|
56
|
+
# ISO 3361 code : GE
|
57
|
+
# ITU code : 995
|
58
|
+
ItuCodes.itu2iso('995') # => ["GE"]
|
59
|
+
|
60
|
+
[1]: http://www.itu.int/itudoc/itu-t/ob-lists/icc/e212_685.pdf
|
61
|
+
[2]: http://www.itu.int/dms_pub/itu-t/opb/sp/T-SP-E.164D-11-2011-PDF-E.pdf
|