e164 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -54,7 +54,7 @@ Just like the CountryCodes, NDC info is stored in a hash of hashes and accessed
54
54
 
55
55
  E164::NANP('303') #=> {:abbreviation => 'Colorado', :description => '[Colorado] (Boulder, Longmont, Aurora, Denver and central Colorado, overlays with [720])', :info => 'en.wikipedia.com.org/wiki/Area_codes_303_and_720'}
56
56
 
57
- E164::Austria['1'] => {:description => 'Wient'}
57
+ E164::Austria['1'] => {:description => 'Wien'}
58
58
 
59
59
  E164::Germany['10'] => {:description => 'Call-By-Call'}
60
60
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{e164}
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{hexorx}]
12
- s.date = %q{2011-11-03}
12
+ s.date = %q{2011-12-30}
13
13
  s.description = %q{The e164 gem can parse and normalize numbers into the e164 format.
14
14
  It provides extra information on the Country Code and National Destination Codes.
15
15
  It can be used standalone or mixed into a model.}
@@ -1,30 +1,40 @@
1
1
  module E164
2
-
2
+
3
3
  Dir.glob(File.join(File.dirname(__FILE__), 'e164/*.rb')).each {|f| require f }
4
-
4
+
5
5
  ValidFormat = /^\+([\d]{1,3})([\d]{1,14})$/
6
6
  Identifiers = ['+','011', '00']
7
7
  DefaultIdentifier = '+'
8
8
  DefaultCountryCode = '1' # Override by E164.set_default_country_code!()
9
-
9
+ DefaultCountryLength = 10 # Override by E164.set_default_country_length!()
10
+
11
+ def self.country_codes
12
+ CountryCodes
13
+ end
14
+
10
15
  def self.normalize(num)
11
16
  parse(num).unshift(DefaultIdentifier).join
12
17
  end
13
-
18
+
14
19
  def self.parse(num)
15
20
  num = e164_clean(num)
16
21
  identifier = Identifiers.include?(num.first) ? num.shift : nil
17
-
18
- num = (identifier || num.join.start_with?(DefaultCountryCode)) ? join_country_code(num) : num.unshift(DefaultCountryCode)
19
- num = join_national_destination_code(num)
20
-
22
+
23
+ if identifier || num.join.start_with?(DefaultCountryCode)
24
+ num = join_country_code(num)
25
+ else
26
+ num = num.unshift(DefaultCountryCode) if num.join.length == DefaultCountryLength
27
+ end
28
+
29
+ num = join_national_destination_code(num) if CountryCodes[num[0]]
30
+
21
31
  [num.shift,num.shift,num.join]
22
32
  end
23
-
33
+
24
34
  def self.e164_clean(num)
25
35
  num.scan(/^(?:#{Identifiers.map{|i| Regexp.escape(i) }.join('|')})|[\d]/)
26
36
  end
27
-
37
+
28
38
  def self.join_country_code(num)
29
39
  potentials = (1..3).map {|l| num[0,l].join}
30
40
  country_code = potentials.map {|x| CountryCodes[x] ? x : nil}.compact.first
@@ -33,13 +43,13 @@ module E164
33
43
  country_code = DefaultCountryCode
34
44
  num.unshift(country_code)
35
45
  end
36
-
46
+
37
47
  [num.shift(country_code.length).join, *num]
38
48
  end
39
-
49
+
40
50
  def self.join_national_destination_code(num)
41
51
  country = CountryCodes[num[0]]
42
-
52
+
43
53
  case (destination_codes = country[:national_destination_codes])
44
54
  when Integer
45
55
  destination_code_length = destination_codes
@@ -48,7 +58,7 @@ module E164
48
58
  destination_code = potentials.map {|x| destination_codes[x] ? x : nil}.compact.first
49
59
  destination_code_length = (destination_code && destination_code.length) || destination_codes[:default]
50
60
  end
51
-
61
+
52
62
  [num.shift, num.shift(destination_code_length).join, *num]
53
63
  end
54
64
 
@@ -57,4 +67,10 @@ module E164
57
67
  const_set(:DefaultCountryCode, country_code)
58
68
  ret_value
59
69
  end
70
+
71
+ def self.set_default_country_length!(country_length)
72
+ ret_value = remove_const(:DefaultCountryLength)
73
+ const_set(:DefaultCountryLength, country_length)
74
+ ret_value
75
+ end
60
76
  end
@@ -5,10 +5,10 @@ Dir.glob(File.join(File.dirname(__FILE__), 'national_destination_codes/*.rb')).e
5
5
  CountryCodes = {
6
6
  '1' => {:national_destination_codes => 3, :abbreviation => 'NANP', :description => 'North American Numbering Plan', :info => 'en.wikipedia.com.org/wiki/NANP'},
7
7
  '7' => {:national_destination_codes => 3, :abbreviation => '', :description => 'Russia', :info => 'en.wikipedia.com.org/wiki/Russia'},
8
-
8
+
9
9
  '20' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Egypt', :info => 'en.wikipedia.com.org/wiki/Egypt'},
10
10
  '27' => {:national_destination_codes => 2, :abbreviation => '', :description => 'South Africa', :info => 'en.wikipedia.com.org/wiki/South_Africa'},
11
-
11
+
12
12
  '30' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Greece', :info => 'en.wikipedia.com.org/wiki/Greece'},
13
13
  '31' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Netherlands', :info => 'en.wikipedia.com.org/wiki/Netherlands'},
14
14
  '32' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Belgium', :info => 'en.wikipedia.com.org/wiki/Belgium'},
@@ -16,7 +16,7 @@ CountryCodes = {
16
16
  '34' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Spain', :info => 'en.wikipedia.com.org/wiki/Spain'},
17
17
  '36' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Hungary', :info => 'en.wikipedia.com.org/wiki/Hungary'},
18
18
  '39' => {:national_destination_codes => 3, :abbreviation => '', :description => 'Italy', :info => 'en.wikipedia.com.org/wiki/Italy'},
19
-
19
+
20
20
  '40' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Romania', :info => 'en.wikipedia.com.org/wiki/Romania'},
21
21
  '41' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Switzerland', :info => 'en.wikipedia.com.org/wiki/Switzerland'},
22
22
  '43' => {:national_destination_codes => Austria, :abbreviation => '', :description => 'Austria', :info => 'en.wikipedia.com.org/wiki/Austria'},
@@ -26,7 +26,7 @@ CountryCodes = {
26
26
  '47' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Norway', :info => 'en.wikipedia.com.org/wiki/Norway'},
27
27
  '48' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Poland', :info => 'en.wikipedia.com.org/wiki/Poland'},
28
28
  '49' => {:national_destination_codes => Germany, :abbreviation => '', :description => 'Germany', :info => 'en.wikipedia.com.org/wiki/Germany'},
29
-
29
+
30
30
  '51' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Peru', :info => 'en.wikipedia.com.org/wiki/Peru'},
31
31
  '52' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Mexico', :info => 'en.wikipedia.com.org/wiki/Mexico'},
32
32
  '53' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Cuba', :info => 'en.wikipedia.com.org/wiki/Cuba'},
@@ -35,7 +35,7 @@ CountryCodes = {
35
35
  '56' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Chile', :info => 'en.wikipedia.com.org/wiki/Chile'},
36
36
  '57' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Colombia', :info => 'en.wikipedia.com.org/wiki/Colombia'},
37
37
  '58' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Venezuela', :info => 'en.wikipedia.com.org/wiki/Venezuela'},
38
-
38
+
39
39
  '60' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Malaysia', :info => 'en.wikipedia.com.org/wiki/Malaysia'},
40
40
  '61' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Australia', :info => 'en.wikipedia.com.org/wiki/Australia'},
41
41
  '62' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Indonesia', :info => 'en.wikipedia.com.org/wiki/Indonesia'},
@@ -43,12 +43,12 @@ CountryCodes = {
43
43
  '64' => {:national_destination_codes => 1, :abbreviation => '', :description => 'New Zealand', :info => 'en.wikipedia.com.org/wiki/New_Zealand'},
44
44
  '65' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Singapore', :info => 'en.wikipedia.com.org/wiki/Singapore'},
45
45
  '66' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Thailand', :info => 'en.wikipedia.com.org/wiki/Thailand'},
46
-
46
+
47
47
  '81' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Japan', :info => 'en.wikipedia.com.org/wiki/Japan'},
48
48
  '82' => {:national_destination_codes => 2, :abbreviation => '', :description => 'South Korea', :info => 'en.wikipedia.com.org/wiki/South_Korea'},
49
49
  '84' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Vietnam', :info => 'en.wikipedia.com.org/wiki/Vietnam'},
50
50
  '86' => {:national_destination_codes => 2, :abbreviation => '', :description => 'People\'s Republic of China', :info => 'en.wikipedia.com.org/wiki/People%27s_Republic_of_China'},
51
-
51
+
52
52
  '90' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Turkey', :info => 'en.wikipedia.com.org/wiki/Turkey'},
53
53
  '91' => {:national_destination_codes => 2, :abbreviation => '', :description => 'India', :info => 'en.wikipedia.com.org/wiki/India'},
54
54
  '92' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Pakistan', :info => 'en.wikipedia.com.org/wiki/Pakistan'},
@@ -56,12 +56,12 @@ CountryCodes = {
56
56
  '94' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Sri Lanka', :info => 'en.wikipedia.com.org/wiki/Sri_Lanka'},
57
57
  '95' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Burma', :info => 'en.wikipedia.com.org/wiki/Burma'},
58
58
  '98' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Iran', :info => 'en.wikipedia.com.org/wiki/Iran'},
59
-
59
+
60
60
  '212' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Morocco', :info => 'en.wikipedia.com.org/wiki/Morocco'},
61
61
  '213' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Algeria', :info => 'en.wikipedia.com.org/wiki/Algeria'},
62
62
  '216' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Tunisia', :info => 'en.wikipedia.com.org/wiki/Tunisia'},
63
63
  '218' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Libya', :info => 'en.wikipedia.com.org/wiki/Libya'},
64
-
64
+
65
65
  '220' => {:national_destination_codes => 2, :abbreviation => '', :description => 'The Gambia', :info => 'en.wikipedia.com.org/wiki/The_Gambia'},
66
66
  '221' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Senegal', :info => 'en.wikipedia.com.org/wiki/Senegal'},
67
67
  '222' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Mauritania', :info => 'en.wikipedia.com.org/wiki/Mauritania'},
@@ -72,7 +72,7 @@ CountryCodes = {
72
72
  '227' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Niger', :info => 'en.wikipedia.com.org/wiki/Niger'},
73
73
  '228' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Togo', :info => 'en.wikipedia.com.org/wiki/Togo'},
74
74
  '229' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Benin', :info => 'en.wikipedia.com.org/wiki/Benin'},
75
-
75
+
76
76
  '230' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Mauritius', :info => 'en.wikipedia.com.org/wiki/Mauritius'},
77
77
  '231' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Liberia', :info => 'en.wikipedia.com.org/wiki/Liberia'},
78
78
  '232' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Sierra Leone', :info => 'en.wikipedia.com.org/wiki/Sierra_Leone'},
@@ -83,7 +83,7 @@ CountryCodes = {
83
83
  '237' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Cameroon', :info => 'en.wikipedia.com.org/wiki/Cameroon'},
84
84
  '238' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Cape Verde', :info => 'en.wikipedia.com.org/wiki/Cape_Verde'},
85
85
  '239' => {:national_destination_codes => 2, :abbreviation => '', :description => 'São Tomé and Príncipe', :info => 'en.wikipedia.com.org/wiki/S%C3%A3o_Tom%C3%A9_and_Pr%C3%ADncipe'},
86
-
86
+
87
87
  '240' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Equatorial Guinea', :info => 'en.wikipedia.com.org/wiki/Equatorial_Guinea'},
88
88
  '241' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Gabon', :info => 'en.wikipedia.com.org/wiki/Gabon'},
89
89
  '242' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Republic of the Congo', :info => 'en.wikipedia.com.org/wiki/Republic_of_the_Congo'},
@@ -94,7 +94,7 @@ CountryCodes = {
94
94
  '247' => {:national_destination_codes => 2, :abbreviation => '', :description => 'United Kingdom', :info => 'en.wikipedia.com.org/wiki/United_Kingdom'},
95
95
  '248' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Seychelles', :info => 'en.wikipedia.com.org/wiki/Seychelles'},
96
96
  '249' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Sudan', :info => 'en.wikipedia.com.org/wiki/Sudan'},
97
-
97
+
98
98
  '250' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Rwanda', :info => 'en.wikipedia.com.org/wiki/Rwanda'},
99
99
  '251' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Ethiopia', :info => 'en.wikipedia.com.org/wiki/Ethiopia'},
100
100
  '252' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Somalia', :info => 'en.wikipedia.com.org/wiki/Somalia'},
@@ -104,7 +104,7 @@ CountryCodes = {
104
104
  '256' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Uganda', :info => 'en.wikipedia.com.org/wiki/Uganda'},
105
105
  '257' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Burundi', :info => 'en.wikipedia.com.org/wiki/Burundi'},
106
106
  '258' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Mozambique', :info => 'en.wikipedia.com.org/wiki/Mozambique'},
107
-
107
+
108
108
  '260' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Zambia', :info => 'en.wikipedia.com.org/wiki/Zambia'},
109
109
  '261' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Madagascar', :info => 'en.wikipedia.com.org/wiki/Madagascar'},
110
110
  '262' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Mayotte', :info => 'en.wikipedia.com.org/wiki/Mayotte'},
@@ -115,13 +115,13 @@ CountryCodes = {
115
115
  '267' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Botswana', :info => 'en.wikipedia.com.org/wiki/Botswana'},
116
116
  '268' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Swaziland', :info => 'en.wikipedia.com.org/wiki/Swaziland'},
117
117
  '269' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Comoros', :info => 'en.wikipedia.com.org/wiki/Comoros'},
118
-
118
+
119
119
  '290' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Saint Helena', :info => 'en.wikipedia.com.org/wiki/Saint_Helena'},
120
120
  '291' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Eritrea', :info => 'en.wikipedia.com.org/wiki/Eritrea'},
121
121
  '297' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Aruba', :info => 'en.wikipedia.com.org/wiki/Aruba'},
122
122
  '298' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Faroe Islands', :info => 'en.wikipedia.com.org/wiki/Faroe_Islands'},
123
123
  '299' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Greenland', :info => 'en.wikipedia.com.org/wiki/Greenland'},
124
-
124
+
125
125
  '350' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Gibraltar', :info => 'en.wikipedia.com.org/wiki/Gibraltar'},
126
126
  '351' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Portugal', :info => 'en.wikipedia.com.org/wiki/Portugal'},
127
127
  '352' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Luxembourg', :info => 'en.wikipedia.com.org/wiki/Luxembourg'},
@@ -132,7 +132,7 @@ CountryCodes = {
132
132
  '357' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Cyprus', :info => 'en.wikipedia.com.org/wiki/Cyprus'},
133
133
  '358' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Finland', :info => 'en.wikipedia.com.org/wiki/Finland'},
134
134
  '359' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Bulgaria', :info => 'en.wikipedia.com.org/wiki/Bulgaria'},
135
-
135
+
136
136
  '370' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Lithuania', :info => 'en.wikipedia.com.org/wiki/Lithuania'},
137
137
  '371' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Latvia', :info => 'en.wikipedia.com.org/wiki/Latvia'},
138
138
  '372' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Estonia', :info => 'en.wikipedia.com.org/wiki/Estonia'},
@@ -143,7 +143,7 @@ CountryCodes = {
143
143
  '377' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Monaco', :info => 'en.wikipedia.com.org/wiki/Monaco'},
144
144
  '378' => {:national_destination_codes => 2, :abbreviation => '', :description => 'discontinued (was assigned to [San Marino], see [+378])', :info => ''},
145
145
  '379' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Vatican City', :info => 'en.wikipedia.com.org/wiki/Vatican_City'},
146
-
146
+
147
147
  '380' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Ukraine', :info => 'en.wikipedia.com.org/wiki/Ukraine'},
148
148
  '381' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Serbia', :info => 'en.wikipedia.com.org/wiki/Serbia'},
149
149
  '382' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Montenegro', :info => 'en.wikipedia.com.org/wiki/Montenegro'},
@@ -152,11 +152,11 @@ CountryCodes = {
152
152
  '387' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Bosnia and Herzegovina', :info => 'en.wikipedia.com.org/wiki/Bosnia_and_Herzegovina'},
153
153
  '388' => {:national_destination_codes => 2, :abbreviation => '', :description => 'shared code for groups of nations', :info => ''},
154
154
  '389' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Republic of Macedonia', :info => 'en.wikipedia.com.org/wiki/Republic_of_Macedonia'},
155
-
155
+
156
156
  '420' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Czech Republic', :info => 'en.wikipedia.com.org/wiki/Czech_Republic'},
157
157
  '421' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Slovakia', :info => 'en.wikipedia.com.org/wiki/Slovakia'},
158
158
  '423' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Liechtenstein', :info => 'en.wikipedia.com.org/wiki/Liechtenstein'},
159
-
159
+
160
160
  '500' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Falkland Islands', :info => 'en.wikipedia.com.org/wiki/Falkland_Islands'},
161
161
  '501' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Belize', :info => 'en.wikipedia.com.org/wiki/Belize'},
162
162
  '502' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Guatemala', :info => 'en.wikipedia.com.org/wiki/Guatemala'},
@@ -167,7 +167,7 @@ CountryCodes = {
167
167
  '507' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Panama', :info => 'en.wikipedia.com.org/wiki/Panama'},
168
168
  '508' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Saint Pierre and Miquelon', :info => 'en.wikipedia.com.org/wiki/Saint_Pierre_and_Miquelon'},
169
169
  '509' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Haiti', :info => 'en.wikipedia.com.org/wiki/Haiti'},
170
-
170
+
171
171
  '590' => {:national_destination_codes => 3, :abbreviation => '', :description => 'Guadeloupe', :info => 'en.wikipedia.com.org/wiki/Guadeloupe'},
172
172
  '591' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Bolivia', :info => 'en.wikipedia.com.org/wiki/Bolivia'},
173
173
  '592' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Guyana', :info => 'en.wikipedia.com.org/wiki/Guyana'},
@@ -178,7 +178,7 @@ CountryCodes = {
178
178
  '597' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Suriname', :info => 'en.wikipedia.com.org/wiki/Suriname'},
179
179
  '598' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Uruguay', :info => 'en.wikipedia.com.org/wiki/Uruguay'},
180
180
  '599' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Netherlands Antilles', :info => 'en.wikipedia.com.org/wiki/Netherlands_Antilles'},
181
-
181
+
182
182
  '670' => {:national_destination_codes => 2, :abbreviation => '', :description => 'East Timor', :info => 'en.wikipedia.com.org/wiki/East_Timor'},
183
183
  '672' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Australia', :info => 'en.wikipedia.com.org/wiki/Australia'},
184
184
  '673' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Brunei', :info => 'en.wikipedia.com.org/wiki/Brunei'},
@@ -188,7 +188,7 @@ CountryCodes = {
188
188
  '677' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Solomon Islands', :info => 'en.wikipedia.com.org/wiki/Solomon_Islands'},
189
189
  '678' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Vanuatu', :info => 'en.wikipedia.com.org/wiki/Vanuatu'},
190
190
  '679' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Fiji', :info => 'en.wikipedia.com.org/wiki/Fiji'},
191
-
191
+
192
192
  '680' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Palau', :info => 'en.wikipedia.com.org/wiki/Palau'},
193
193
  '681' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Wallis and Futuna', :info => 'en.wikipedia.com.org/wiki/Wallis_and_Futuna'},
194
194
  '682' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Cook Islands', :info => 'en.wikipedia.com.org/wiki/Cook_Islands'},
@@ -198,34 +198,34 @@ CountryCodes = {
198
198
  '687' => {:national_destination_codes => 2, :abbreviation => '', :description => 'New Caledonia', :info => 'en.wikipedia.com.org/wiki/New_Caledonia'},
199
199
  '688' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Tuvalu', :info => 'en.wikipedia.com.org/wiki/Tuvalu'},
200
200
  '689' => {:national_destination_codes => 2, :abbreviation => '', :description => 'French Polynesia', :info => 'en.wikipedia.com.org/wiki/French_Polynesia'},
201
-
201
+
202
202
  '690' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Tokelau', :info => 'en.wikipedia.com.org/wiki/Tokelau'},
203
203
  '691' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Federated States of Micronesia', :info => 'en.wikipedia.com.org/wiki/Federated_States_of_Micronesia'},
204
204
  '692' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Marshall Islands', :info => 'en.wikipedia.com.org/wiki/Marshall_Islands'},
205
-
205
+
206
206
  '800' => {:national_destination_codes => 2, :abbreviation => '', :description => 'International Freephone ([UIFN])', :info => ''},
207
207
  '808' => {:national_destination_codes => 2, :abbreviation => '', :description => 'reserved for [Shared Cost Services]', :info => ''},
208
-
208
+
209
209
  '850' => {:national_destination_codes => 2, :abbreviation => '', :description => 'North Korea', :info => 'en.wikipedia.com.org/wiki/North_Korea'},
210
210
  '852' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Hong Kong', :info => 'en.wikipedia.com.org/wiki/Hong_Kong'},
211
211
  '853' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Macau', :info => 'en.wikipedia.com.org/wiki/Macau'},
212
212
  '855' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Cambodia', :info => 'en.wikipedia.com.org/wiki/Cambodia'},
213
213
  '856' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Laos', :info => 'en.wikipedia.com.org/wiki/Laos'},
214
-
214
+
215
215
  '870' => {:national_destination_codes => 2, :abbreviation => '', :description => '[Inmarsat] "SNAC" service', :info => ''},
216
216
  '875' => {:national_destination_codes => 2, :abbreviation => '', :description => 'reserved for Maritime Mobile service', :info => ''},
217
217
  '876' => {:national_destination_codes => 2, :abbreviation => '', :description => 'reserved for Maritime Mobile service', :info => ''},
218
218
  '877' => {:national_destination_codes => 2, :abbreviation => '', :description => 'reserved for Maritime Mobile service', :info => ''},
219
219
  '878' => {:national_destination_codes => 2, :abbreviation => '', :description => '[Universal Personal Telecommunications] services', :info => ''},
220
220
  '879' => {:national_destination_codes => 2, :abbreviation => '', :description => 'reserved for national non', :info => ''},
221
-
221
+
222
222
  '880' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Bangladesh', :info => 'en.wikipedia.com.org/wiki/Bangladesh'},
223
223
  '881' => {:national_destination_codes => 2, :abbreviation => '', :description => '[Global Mobile Satellite System]', :info => ''},
224
224
  '882' => {:national_destination_codes => 2, :abbreviation => '', :description => '[International Networks]', :info => ''},
225
225
  '883' => {:national_destination_codes => 2, :abbreviation => '', :description => '[International Networks]', :info => ''},
226
226
  '886' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Republic of China', :info => 'en.wikipedia.com.org/wiki/Republic_of_China'},
227
227
  '888' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Telecommunications for Disaster Relief by [OCHA]', :info => ''},
228
-
228
+
229
229
  '960' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Maldives', :info => 'en.wikipedia.com.org/wiki/Maldives'},
230
230
  '961' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Lebanon', :info => 'en.wikipedia.com.org/wiki/Lebanon'},
231
231
  '962' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Jordan', :info => 'en.wikipedia.com.org/wiki/Jordan'},
@@ -236,7 +236,7 @@ CountryCodes = {
236
236
  '967' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Yemen', :info => 'en.wikipedia.com.org/wiki/Yemen'},
237
237
  '968' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Oman', :info => 'en.wikipedia.com.org/wiki/Oman'},
238
238
  '969' => {:national_destination_codes => 2, :abbreviation => '', :description => 'formerly [People\'s Democratic Republic of Yemen]', :info => ''},
239
-
239
+
240
240
  '970' => {:national_destination_codes => 2, :abbreviation => '', :description => 'reserved (for the [Palestinian Authority]).', :info => ''},
241
241
  '971' => {:national_destination_codes => 2, :abbreviation => '', :description => 'United Arab Emirates', :info => 'en.wikipedia.com.org/wiki/United_Arab_Emirates'},
242
242
  '972' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Israel', :info => 'en.wikipedia.com.org/wiki/Israel'},
@@ -246,7 +246,7 @@ CountryCodes = {
246
246
  '976' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Mongolia', :info => 'en.wikipedia.com.org/wiki/Mongolia'},
247
247
  '977' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Nepal', :info => 'en.wikipedia.com.org/wiki/Nepal'},
248
248
  '979' => {:national_destination_codes => 2, :abbreviation => '', :description => '[International Premium Rate Service]', :info => ''},
249
-
249
+
250
250
  '991' => {:national_destination_codes => 2, :abbreviation => '', :description => '[International Telecommunications Public Correspondence Service trial] (ITPCS)', :info => ''},
251
251
  '992' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Tajikistan', :info => 'en.wikipedia.com.org/wiki/Tajikistan'},
252
252
  '993' => {:national_destination_codes => 2, :abbreviation => '', :description => 'Turkmenistan', :info => 'en.wikipedia.com.org/wiki/Turkmenistan'},
@@ -1,46 +1,55 @@
1
+ # 050 are Private networks according to RTR: http://www.rtr.at/index.php?S=050&id=4506&L=&submit_TK=Suchen
2
+ # 67 and 68 are not completely mobile services.
3
+ # some ranges are used and some are note alocated, details: http://www.rtr.at/index.php?S=067&id=4506&L=&submit_TK=Suchen
4
+
1
5
  Austria = {
2
6
  :range => 1..3,
3
7
  :default => 3,
4
- '1' => {:description => 'Wient'},
8
+ '1' => {:description => 'Wien'},
9
+ '50' => {:description => 'Private Networks'},
5
10
  '57' => {:description => '-'},
6
11
  '59' => {:description => '-'},
7
- '67' => {:description => 'Mobile Services'},
8
- '68' => {:description => 'Mobile Services'},
12
+ # '67' => {:description => 'Mobile Services'},
13
+ # '68' => {:description => 'Mobile Services'},
9
14
  '89' => {:description => 'Routing Number'},
10
15
  '316' => {:description => 'Graz'},
11
- '501' => {:description => '-'},
12
- '502' => {:description => '-'},
13
- '503' => {:description => '-'},
14
- '504' => {:description => '-'},
15
- '505' => {:description => '-'},
16
- '506' => {:description => '-'},
17
- '507' => {:description => '-'},
18
- '508' => {:description => '-'},
19
- '509' => {:description => '-'},
16
+ # '501' => {:description => '-'},
17
+ # '502' => {:description => '-'},
18
+ # '503' => {:description => '-'},
19
+ # '504' => {:description => '-'},
20
+ # '505' => {:description => '-'},
21
+ # '506' => {:description => '-'},
22
+ # '507' => {:description => '-'},
23
+ # '508' => {:description => '-'},
24
+ # '509' => {:description => '-'},
20
25
  '512' => {:description => 'Innsbruck'},
21
26
  '517' => {:description => '-'},
22
27
  '644' => {:description => 'Mobile Services'},
23
- '650' => {:description => 'Mobile Services'},
28
+ '650' => {:description => 'Mobile Services Tele.Ring'},
24
29
  '651' => {:description => 'Mobile Services'},
25
30
  '652' => {:description => 'Mobile Services'},
26
31
  '653' => {:description => 'Mobile Services'},
27
32
  '655' => {:description => 'Mobile Services'},
28
33
  '657' => {:description => 'Mobile Services'},
29
34
  '659' => {:description => 'Mobile Services'},
30
- '660' => {:description => 'Mobile Services'},
35
+ '660' => {:description => 'Mobile Services H3G'},
31
36
  '661' => {:description => 'Mobile Services'},
32
37
  '662' => {:description => 'Salzburg'},
33
38
  '663' => {:description => 'Mobile Services'},
34
- '664' => {:description => 'Mobile Services'},
39
+ '664' => {:description => 'Mobile Services A1'},
35
40
  '665' => {:description => 'Mobile Services'},
36
41
  '666' => {:description => 'Mobile Services'},
37
42
  '667' => {:description => 'Mobile Services'},
38
43
  '668' => {:description => 'Mobile Services'},
39
44
  '669' => {:description => 'Mobile Services'},
45
+ '676' => {:description => 'Mobile Services T-Mobile'},
46
+ '680' => {:description => 'Mobile Services Bob'},
47
+ '681' => {:description => 'Mobile Services Yesss!'},
48
+ '699' => {:description => 'Mobile Services Orange'},
40
49
  '710' => {:description => 'Service Number'},
41
50
  '711' => {:description => 'Service Number'},
42
51
  '718' => {:description => 'Service Number'},
43
- '720' => {:description => ''},
52
+ '720' => {:description => 'VoIP'},
44
53
  '730' => {:description => 'Service Number'},
45
54
  '732' => {:description => 'Linz'},
46
55
  '740' => {:description => 'Service Number'},
@@ -4,7 +4,7 @@ describe E164 do
4
4
  it 'should set ValidFormat to regex that validates e164' do
5
5
  '+13035559850'.should =~ E164::ValidFormat
6
6
  end
7
-
7
+
8
8
  it 'should set DefaultCountryCode to 1(NANP)' do
9
9
  E164::DefaultCountryCode.should == '1'
10
10
  end
@@ -20,20 +20,42 @@ describe E164 do
20
20
  end
21
21
  end
22
22
  end
23
-
23
+
24
+ describe "#country_codes" do
25
+ it 'should search country code hash' do
26
+ E164.country_codes['1'].should == {:national_destination_codes=>3, :abbreviation=>"NANP", :description=>"North American Numbering Plan", :info=>"en.wikipedia.com.org/wiki/NANP"}
27
+ end
28
+ end
29
+
30
+ describe '#set_default_country_length!' do
31
+ it 'should override DefaultCountryLength' do
32
+ original = E164.set_default_country_length!('12')
33
+ begin
34
+ E164::DefaultCountryLength.should == '12'
35
+ ensure
36
+ # set back original DefaultCountryLength's value
37
+ E164.set_default_country_length!(original)
38
+ end
39
+ end
40
+ end
41
+
24
42
  describe '#normalize' do
25
43
  it 'should remove all non-numeric punctuation except the e164 identifier prefix' do
26
44
  E164.normalize('+1 (303) 555-9850').should == '+13035559850'
27
45
  end
28
-
46
+
29
47
  it 'should add default country code if no country code e164 identifier is found.' do
30
48
  E164.normalize('3035559850').should == "+13035559850"
31
49
  end
32
-
50
+
51
+ it 'should not add default country code if the number is longer than default country length' do
52
+ E164.normalize('447966845555').should == '+447966845555'
53
+ end
54
+
33
55
  it 'should not add country code if it already starts with the default country code and no identifier' do
34
56
  E164.normalize('13035559850').should == "+13035559850"
35
57
  end
36
-
58
+
37
59
  it "shouldn't die on german numbers" do
38
60
  lambda { E164.normalize('+4988612345670') }.should_not raise_error
39
61
  end
@@ -7,5 +7,5 @@ require 'e164'
7
7
  Bundler.require(:default, :test) if defined?(Bundler)
8
8
 
9
9
  RSpec.configure do |config|
10
- config.mock_with :rspec
10
+ config.mock_with :rspec
11
11
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: e164
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 1
10
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - hexorx
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-03 00:00:00 Z
18
+ date: 2011-12-30 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement