itu_codes 0.4.7 → 0.4.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.
- data/README.md +5 -3
- data/lib/itu_codes.rb +19 -0
- data/lib/itu_codes/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -9,10 +9,10 @@ Country code lookup based on official ISO-3166-1 specifications:
|
|
9
9
|
* [Country Codes - ISO 3166][3]
|
10
10
|
* [list of alpha-2 country codes in XML format][4]
|
11
11
|
|
12
|
-
The main goal of this library is to closely match the latest official specifications from the ITU and
|
12
|
+
The main goal of this library is to closely match the latest official specifications from the [ITU][5], [ISO][6], [NANPA][7] and other governing bodies relating to calling codes. If you find any discrepancies in the data, please let me know!
|
13
13
|
|
14
14
|
Some complicating factors when dealing with calling codes:
|
15
|
-
* In North America, 25 countries and territories follow the [North American Numbering Plan][
|
15
|
+
* In North America, 25 countries and territories follow the [North American Numbering Plan][7] and share the ITU code '1'.
|
16
16
|
* Russia and Kazakhstan share the ITU code '7'.
|
17
17
|
* The ITU does not use ISO 3166 alpha-2 codes to specify countries or regions in its documents.
|
18
18
|
* In general, each ITU code corresponds to exactly one ISO 3166 code. However, there are exceptions. For examples, the Australian External Territories have a single ITU code of '672', but have 4 distinct ISO 3166 codes (CC, CX, HM, NF).
|
@@ -119,4 +119,6 @@ ItuCodes.compatriots? '1264', '1818'
|
|
119
119
|
[2]: http://www.itu.int/dms_pub/itu-t/opb/sp/T-SP-E.164D-11-2011-PDF-E.pdf
|
120
120
|
[3]: http://www.iso.org/iso/home/standards/country_codes
|
121
121
|
[4]: http://www.iso.org/iso/home/standards/country_codes/country_names_and_code_elements_xml
|
122
|
-
[5]: http://www.
|
122
|
+
[5]: http://www.itu.int
|
123
|
+
[6]: http://www.iso.org
|
124
|
+
[7]: http://www.nanpa.com
|
data/lib/itu_codes.rb
CHANGED
@@ -99,9 +99,28 @@ module ItuCodes
|
|
99
99
|
some_number[0,sub_index] unless sub_index.nil?
|
100
100
|
end
|
101
101
|
|
102
|
+
# parse a north american full number and return the area code
|
103
|
+
# returns nil if the number is not north american
|
104
|
+
# return 1, if can't find an area code in Constants::NORTH_AMERICAN_AREA_CODES
|
105
|
+
# ex: north_american_area_code_for("1-264-9568543") => 1264
|
106
|
+
def north_american_area_code_for(some_number)
|
107
|
+
some_number = clean(some_number)
|
108
|
+
|
109
|
+
itu_code = parse_code(some_number)
|
110
|
+
|
111
|
+
return nil if itu_code.nil? || !north_american?(itu_code)
|
112
|
+
|
113
|
+
code = itu_code
|
114
|
+
|
115
|
+
north_american_codes.each { |_, v| code = some_number[0,4] if v.include?(some_number[0,4]) }
|
116
|
+
|
117
|
+
return code
|
118
|
+
end
|
119
|
+
|
102
120
|
# parse a destination code (probably with area code) to find the number without the ITU code
|
103
121
|
# ex: parse_number(18184443322) => 8184443322
|
104
122
|
def parse_number(some_number)
|
123
|
+
some_number = clean(some_number)
|
105
124
|
country_code = parse_code(some_number)
|
106
125
|
some_number[country_code.length,some_number.length] unless country_code.nil?
|
107
126
|
end
|
data/lib/itu_codes/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|