phony 1.0.1 → 1.1.0

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.
Files changed (41) hide show
  1. data/README.textile +14 -2
  2. data/lib/phony.rb +58 -463
  3. data/lib/phony/countries/all_other.rb +417 -0
  4. data/lib/phony/countries/austria.rb +69 -0
  5. data/lib/phony/countries/egypt.rb +40 -0
  6. data/lib/phony/countries/germany.rb +156 -0
  7. data/lib/phony/countries/greece.rb +30 -0
  8. data/lib/phony/countries/hungary.rb +23 -0
  9. data/lib/phony/countries/italy.rb +105 -0
  10. data/lib/phony/country.rb +102 -0
  11. data/lib/phony/country_codes.rb +102 -0
  12. data/lib/phony/local_splitter.rb +46 -0
  13. data/lib/phony/national_code.rb +27 -0
  14. data/lib/phony/national_splitters/fixed.rb +36 -0
  15. data/lib/phony/national_splitters/variable.rb +64 -0
  16. data/lib/phony/vanity.rb +35 -0
  17. data/spec/lib/phony/countries/austria_spec.rb +24 -0
  18. data/spec/lib/phony/countries/egypt_spec.rb +18 -0
  19. data/spec/lib/phony/countries/germany_spec.rb +24 -0
  20. data/spec/lib/phony/countries/greece_spec.rb +18 -0
  21. data/spec/lib/phony/countries/hungary_spec.rb +18 -0
  22. data/spec/lib/phony/countries/switzerland_spec.rb +18 -0
  23. data/spec/lib/phony/country_codes_spec.rb +110 -0
  24. data/spec/lib/phony/country_spec.rb +91 -0
  25. data/spec/lib/phony/local_splitter_spec.rb +48 -0
  26. data/spec/lib/phony/national_code_spec.rb +36 -0
  27. data/spec/lib/phony/national_splitters/fixed_spec.rb +43 -0
  28. data/spec/lib/phony/national_splitters/variable_spec.rb +35 -0
  29. data/spec/lib/phony/vanity_spec.rb +34 -0
  30. data/spec/lib/phony_spec.rb +117 -238
  31. metadata +45 -21
  32. data/lib/ndc/austria.rb +0 -69
  33. data/lib/ndc/fixed_size.rb +0 -113
  34. data/lib/ndc/germany.rb +0 -157
  35. data/lib/ndc/prefix.rb +0 -67
  36. data/lib/ndc/splitter.rb +0 -81
  37. data/spec/lib/ndc/austria_spec.rb +0 -40
  38. data/spec/lib/ndc/fixed_size_spec.rb +0 -65
  39. data/spec/lib/ndc/germany_spec.rb +0 -40
  40. data/spec/lib/ndc/prefix_spec.rb +0 -25
  41. data/spec/lib/ndc/splitter_spec.rb +0 -59
@@ -0,0 +1,417 @@
1
+ # Splits a national number into a fixed size NDC and rest.
2
+ #
3
+ module Phony
4
+ module Countries
5
+
6
+ # Returns an anonymous fixed size ndc / format country handler.
7
+ #
8
+ def self.fixed size, options = {}
9
+ options.merge! :ndc_length => size
10
+ Phony::Country.fixed options
11
+ end
12
+
13
+ # TODO
14
+ #
15
+ def self.with_cc cc
16
+ mapping[cc.size][cc.to_s]
17
+ end
18
+
19
+ # Defines a mapping of country code to all splitters/formatters.
20
+ #
21
+ # Note: The above fixed helper is used.
22
+ # In some cases, we have explicit countries defined.
23
+ #
24
+ # Note: Many taken from http://en.wikipedia.org/wiki/Telephone_numbering_plan.
25
+ #
26
+ def self.mapping
27
+ {
28
+ 1 => {
29
+ '0' => fixed(1), # reserved
30
+ '1' => fixed(3, # USA, Canada, etc.
31
+ :local_format => [3, 4]
32
+ ),
33
+
34
+ # Kazakhstan (Republic of) & Russian Federation
35
+ # http://en.wikipedia.org/wiki/Telephone_numbers_in_Russia
36
+ #
37
+ '7' => fixed(3,
38
+ :local_format => [3, 2, 2]
39
+ ),
40
+ },
41
+ 2 => {
42
+ '20' => Countries::Egypt,
43
+ '27' => fixed(2, # South Africa
44
+ :local_format => [3, 4]
45
+ ),
46
+
47
+ '30' => Countries::Greece,
48
+ '31' => fixed(2), # Netherlands
49
+ '32' => fixed(1, # Belgium
50
+ :local_format => [3, 4]
51
+ ),
52
+ '33' => fixed(1, # France
53
+ :local_format => [2, 2, 2, 2],
54
+ :service_ndcs => %w{8}
55
+ # :special_ndcs => {
56
+ # :service => %w{8},
57
+ # :mobile => %w{6 7}
58
+ # }
59
+ ),
60
+ '34' => fixed(2, # Spain
61
+ :local_format => [3, 4]
62
+ ),
63
+ '36' => Countries::Hungary,
64
+ '39' => Countries::Italy,
65
+
66
+ '40' => fixed(2), # Romania
67
+ '41' => fixed(2, # Switzerland (Confederation of)
68
+ :local_format => [3, 2, 2],
69
+ :service_local_format => [3, 3],
70
+ :service_ndcs => %w{800 840 842 844 848}
71
+ # :special_ndcs => {
72
+ # :service => %w{800 840 842 844 848},
73
+ # :mobile => %w{74 76 77 78 79}
74
+ # }
75
+ ),
76
+ '43' => Countries::Austria,
77
+ '44' => fixed(2), # United Kingdom of Great Britain and Northern Ireland
78
+ '45' => fixed(2), # Denmark
79
+ '46' => fixed(2), # Sweden
80
+ '47' => fixed(4, # Norway
81
+ :local_format => [4]
82
+ ),
83
+ '48' => fixed(2, # Poland (Republic of)
84
+ :local_format => [1, 3, 3] # Approximation. Correct would be 48-xxx-xxx-xxx
85
+ ),
86
+ '49' => Countries::Germany,
87
+
88
+ '51' => fixed(2), # Peru
89
+ '52' => fixed(2), # Mexico
90
+ '53' => fixed(2), # Cuba
91
+ '54' => fixed(2), # Argentine Republic
92
+ '55' => fixed(2), # Brazil (Federative Republic of)
93
+ '56' => fixed(2), # Chile
94
+ '57' => fixed(2), # Colombia (Republic of)
95
+ '58' => fixed(2), # Venezuela (Bolivarian Republic of)
96
+
97
+ '60' => fixed(2), # Malaysia
98
+ '61' => fixed(1, # Australia
99
+ :local_format => [4, 4]
100
+ ),
101
+ '62' => fixed(2), # Indonesia (Republic of)
102
+ '63' => fixed(2), # Philippines (Republic of the)
103
+ '64' => fixed(1, # New Zealand
104
+ :local_format => [3, 4]
105
+ ),
106
+ '65' => fixed(2), # Singapore (Republic of)
107
+ '66' => fixed(2), # Thailand
108
+
109
+ '81' => fixed(2), # Japan
110
+ '82' => fixed(2), # Korea (Republic of)
111
+ '84' => fixed(2), # Viet Nam (Socialist Republic of)
112
+ '86' => fixed(2), # China (People's Republic of)
113
+
114
+ '90' => fixed(2), # Turkey
115
+ '91' => fixed(2), # India (Republic of)
116
+ '92' => fixed(2), # Pakistan (Islamic Republic of)
117
+ '93' => fixed(2), # Afghanistan
118
+ '94' => fixed(2), # Sri Lanka (Democratic Socialist Republic of)
119
+ '95' => fixed(2), # Myanmar (Union of)
120
+ '98' => fixed(2), #Iran (Islamic Republic of)
121
+ },
122
+ 3 => {
123
+ '210' => fixed(2), # -
124
+ '211' => fixed(2), # -
125
+ '212' => fixed(2), # Morocco
126
+ '213' => fixed(2), # Algeria
127
+ '214' => fixed(2), # -
128
+ '215' => fixed(2), # -
129
+ '216' => fixed(2), # Tunisia
130
+ '217' => fixed(2), # -
131
+ '218' => fixed(2), # Lybia
132
+ '219' => fixed(2), # -
133
+
134
+ '220' => fixed(2), # Gambia
135
+ '221' => fixed(2), # Senegal
136
+ '222' => fixed(2), # Mauritania
137
+ '223' => fixed(2), # Mali
138
+ '224' => fixed(2), # Guinea
139
+ '225' => fixed(2), # Côte d'Ivoire
140
+ '226' => fixed(2), # Burkina Faso
141
+ '227' => fixed(2), # Niger
142
+ '228' => fixed(2), # Togolese Republic
143
+ '229' => fixed(2), # Benin
144
+
145
+ '230' => fixed(2), # Mauritius
146
+ '231' => fixed(2), # Liberia
147
+ '232' => fixed(2), # Sierra Leone
148
+ '233' => fixed(2), # Ghana
149
+ '234' => fixed(2), # Nigeria
150
+ '235' => fixed(2), # Chad
151
+ '236' => fixed(2), # Central African Republic
152
+ '237' => fixed(2), # Cameroon
153
+ '238' => fixed(2), # Cape Verde
154
+ '239' => fixed(2), # Sao Tome and Principe
155
+
156
+ '240' => fixed(2), # Equatorial Guinea
157
+ '241' => fixed(2), # Gabonese Republic
158
+ '242' => fixed(2), # Congo
159
+ '243' => fixed(2), # Democratic Republic of the Congo
160
+ '244' => fixed(2), # Angola
161
+ '245' => fixed(2), # Guinea-Bissau
162
+ '246' => fixed(2), # Diego Garcia
163
+ '247' => fixed(2), # Ascension
164
+ '248' => fixed(2), # Seychelles
165
+ '249' => fixed(2), # Sudan
166
+
167
+ '250' => fixed(2), # Rwanda
168
+ '251' => fixed(2), # Ethiopia
169
+ '252' => fixed(2), # Somali Democratic Republic
170
+ '253' => fixed(2), # Djibouti
171
+ '254' => fixed(2), # Kenya
172
+ '255' => fixed(2), # Tanzania
173
+ '256' => fixed(2), # Uganda
174
+ '257' => fixed(2), # Burundi
175
+ '258' => fixed(2), # Mozambique
176
+ '259' => fixed(2), # -
177
+
178
+ '260' => fixed(2), # Zambia
179
+ '261' => fixed(2), # Madagascar
180
+ '262' => fixed(3), # Reunion / Mayotte (new)
181
+ '263' => fixed(2), # Zimbabwe
182
+ '264' => fixed(2), # Namibia
183
+ '265' => fixed(2), # Malawi
184
+ '266' => fixed(2), # Lesotho
185
+ '267' => fixed(2), # Botswana
186
+ '268' => fixed(2), # Swaziland
187
+ '269' => fixed(2), # Comoros
188
+
189
+ '280' => fixed(2), # -
190
+ '281' => fixed(2), # -
191
+ '282' => fixed(2), # -
192
+ '283' => fixed(2), # -
193
+ '284' => fixed(2), # -
194
+ '285' => fixed(2), # -
195
+ '286' => fixed(2), # -
196
+ '287' => fixed(2), # -
197
+ '288' => fixed(2), # -
198
+ '289' => fixed(2), # -
199
+ '290' => fixed(2), # Saint Helena
200
+
201
+ '291' => fixed(2), # Eritrea
202
+ '292' => fixed(2), # -
203
+ '293' => fixed(2), # -
204
+ '294' => fixed(2), # -
205
+ '295' => fixed(2), # -
206
+ '296' => fixed(2), # -
207
+ '297' => fixed(2), # Aruba
208
+ '298' => fixed(2), # Faroe Islands
209
+ '299' => fixed(2), # Greenland
210
+
211
+ '350' => fixed(2), # Gibraltar
212
+ '351' => fixed(2), # Portugal
213
+ '352' => fixed(2), # Luxembourg
214
+ '353' => fixed(2), # Ireland
215
+ '354' => fixed(2), # Iceland
216
+ '355' => fixed(2), # Albania
217
+ '356' => fixed(2), # Malta
218
+ '357' => fixed(2), # Cyprus
219
+ '358' => fixed(2), # Finland
220
+ '359' => fixed(2), # Bulgaria
221
+
222
+ '370' => fixed(2), # Lithuania
223
+ '371' => fixed(2), # Latvia
224
+ '372' => fixed(2), # Estonia
225
+ '373' => fixed(2), # Moldova
226
+ '374' => fixed(2), # Armenia
227
+ '375' => fixed(2), # Belarus
228
+ '376' => fixed(2), # Andorra
229
+ '377' => fixed(2), # Monaco
230
+ '378' => fixed(2), # San Marino
231
+ '379' => fixed(2), # Vatican City State
232
+
233
+ '380' => fixed(2), # Ukraine
234
+ '381' => fixed(2), # Serbia and Montenegro
235
+ '382' => fixed(2), # -
236
+ '383' => fixed(2), # -
237
+ '384' => fixed(2), # -
238
+ '385' => fixed(2), # Croatia
239
+ '386' => fixed(2), # Slovenia
240
+ '387' => fixed(2), # Bosnia and Herzegovina
241
+ '388' => fixed(2), # Group of countries, shared code
242
+ '389' => fixed(2), # The Former Yugoslav Republic of Macedonia
243
+
244
+ '420' => fixed(3, # Czech Republic
245
+ :local_format => [3, 3]
246
+ ),
247
+ '421' => fixed(2), # Slovak Republic
248
+ '422' => fixed(2), # Spare code
249
+ '423' => fixed(0, # Liechtenstein (Principality of)
250
+ :local_format => [3, 2, 2]
251
+ ),
252
+ '424' => fixed(2), # -
253
+ '425' => fixed(2), # -
254
+ '426' => fixed(2), # -
255
+ '427' => fixed(2), # -
256
+ '428' => fixed(2), # -
257
+ '429' => fixed(2), # -
258
+
259
+ '500' => fixed(2), # Falkland Islands (Malvinas)
260
+ '501' => fixed(2), # Belize
261
+ '502' => fixed(2), # Guatemala (Republic of)
262
+ '503' => fixed(2), # El Salvador (Republic of)
263
+ '504' => fixed(2), # Honduras (Republic of)
264
+ '505' => fixed(2), # Nicaragua
265
+ '506' => fixed(2), # Costa Rica
266
+ '507' => fixed(2), # Panama (Republic of)
267
+ '508' => fixed(2), # Saint Pierre and Miquelon (Collectivité territoriale de la République française)
268
+ '509' => fixed(2), # Haiti (Republic of)
269
+
270
+ '590' => fixed(3), # Guadeloupe (French Department of)
271
+ '591' => fixed(2), # Bolivia (Republic of)
272
+ '592' => fixed(2), # Guyana
273
+ '593' => fixed(2), # Ecuador
274
+ '594' => fixed(3), # French Guiana (French Department of)
275
+ '595' => fixed(2), # Paraguay (Republic of)
276
+ '596' => fixed(3), # Martinique (French Department of)
277
+ '597' => fixed(2), # Suriname (Republic of)
278
+ '598' => fixed(2), # Uruguay (Eastern Republic of)
279
+ '599' => fixed(2), # Netherlands Antilles
280
+
281
+ '670' => fixed(2), # Democratic Republic of Timor-Leste
282
+ '671' => fixed(2), # Spare code
283
+ '672' => fixed(2), # Australian External Territories
284
+ '673' => fixed(2), # Brunei Darussalam
285
+ '674' => fixed(2), # Nauru (Republic of)
286
+ '675' => fixed(2), # Papua New Guinea
287
+ '676' => fixed(2), # Tonga (Kingdom of)
288
+ '677' => fixed(2), # Solomon Islands
289
+ '678' => fixed(2), # Vanuatu (Republic of)
290
+ '679' => fixed(2), # Fiji (Republic of)
291
+
292
+ '680' => fixed(2), # Palau (Republic of)
293
+ '681' => fixed(2), # Wallis and Futuna (Territoire français d'outre-mer)
294
+ '682' => fixed(2), # Cook Islands
295
+ '683' => fixed(2), # Niue
296
+ '684' => fixed(2), # -
297
+ '685' => fixed(2), # Samoa (Independent State of)
298
+ '686' => fixed(2), # Kiribati (Republic of)
299
+ '687' => fixed(2), # New Caledonia (Territoire français d'outre-mer)
300
+ '688' => fixed(2), # Tuvalu
301
+ '689' => fixed(2), # French Polynesia (Territoire français d'outre-mer)
302
+
303
+ '690' => fixed(2), # Tokelau
304
+ '691' => fixed(2), # Micronesia (Federated States of)
305
+ '692' => fixed(2), # Marshall Islands (Republic of the)
306
+ '693' => fixed(2), # -
307
+ '694' => fixed(2), # -
308
+ '695' => fixed(2), # -
309
+ '696' => fixed(2), # -
310
+ '697' => fixed(2), # -
311
+ '698' => fixed(2), # -
312
+ '699' => fixed(2), # -
313
+
314
+ '800' => fixed(2), # International Freephone Service
315
+ '801' => fixed(2), # -
316
+ '802' => fixed(2), # -
317
+ '803' => fixed(2), # -
318
+ '804' => fixed(2), # -
319
+ '805' => fixed(2), # -
320
+ '806' => fixed(2), # -
321
+ '807' => fixed(2), # -
322
+ '808' => fixed(2), # International Shared Cost Service (ISCS)
323
+ '809' => fixed(2), # -
324
+
325
+ '830' => fixed(2), # -
326
+ '831' => fixed(2), # -
327
+ '832' => fixed(2), # -
328
+ '833' => fixed(2), # -
329
+ '834' => fixed(2), # -
330
+ '835' => fixed(2), # -
331
+ '836' => fixed(2), # -
332
+ '837' => fixed(2), # -
333
+ '838' => fixed(2), # -
334
+ '839' => fixed(2), # -
335
+
336
+ '850' => fixed(2), # Democratic People's Republic of Korea
337
+ '851' => fixed(2), # Spare code
338
+ '852' => fixed(2), # Hong Kong, China
339
+ '853' => fixed(2), # Macao, China
340
+ '854' => fixed(2), # Spare code
341
+ '855' => fixed(2), # Cambodia (Kingdom of)
342
+ '856' => fixed(2), # Lao People's Democratic Republic
343
+ '857' => fixed(2), # Spare code
344
+ '858' => fixed(2), # Spare code
345
+ '859' => fixed(2), # Spare code
346
+
347
+ '870' => fixed(2), # Inmarsat SNAC
348
+ '871' => fixed(2), # Inmarsat (Atlantic Ocean-East)
349
+ '872' => fixed(2), # Inmarsat (Pacific Ocean)
350
+ '873' => fixed(2), # Inmarsat (Indian Ocean)
351
+ '874' => fixed(2), # Inmarsat (Atlantic Ocean-West)
352
+ '875' => fixed(2), # Reserved - Maritime Mobile Service Applications
353
+ '876' => fixed(2), # Reserved - Maritime Mobile Service Applications
354
+ '877' => fixed(2), # Reserved - Maritime Mobile Service Applications
355
+ '878' => fixed(2), # Universal Personal Telecommunication Service (UPT)
356
+ '879' => fixed(2), # Reserved for national non-commercial purposes
357
+
358
+ '880' => fixed(2), # Bangladesh (People's Republic of)
359
+ '881' => fixed(2), # International Mobile, shared code
360
+ '882' => fixed(2), # International Networks, shared code
361
+ '883' => fixed(2), # -
362
+ '884' => fixed(2), # -
363
+ '885' => fixed(2), # -
364
+ '886' => fixed(2), # Reserved
365
+ '887' => fixed(2), # -
366
+ '888' => fixed(2), # Reserved for future global service
367
+ '889' => fixed(2), # -
368
+
369
+ '890' => fixed(2), # -
370
+ '891' => fixed(2), # -
371
+ '892' => fixed(2), # -
372
+ '893' => fixed(2), # -
373
+ '894' => fixed(2), # -
374
+ '895' => fixed(2), # -
375
+ '896' => fixed(2), # -
376
+ '897' => fixed(2), # -
377
+ '898' => fixed(2), # -
378
+ '899' => fixed(2), # -
379
+
380
+ '960' => fixed(2), # Maldives (Republic of)
381
+ '961' => fixed(2), # Lebanon
382
+ '962' => fixed(2), # Jordan (Hashemite Kingdom of)
383
+ '963' => fixed(2), # Syrian Arab Republic
384
+ '964' => fixed(2), # Iraq (Republic of)
385
+ '965' => fixed(2), # Kuwait (State of)
386
+ '966' => fixed(2), # Saudi Arabia (Kingdom of)
387
+ '967' => fixed(2), # Yemen (Republic of)
388
+ '968' => fixed(2), # Oman (Sultanate of)
389
+ '969' => fixed(2), # Reserved - reservation currently under investigation
390
+
391
+ '970' => fixed(2), # Reserved
392
+ '971' => fixed(2), # United Arab Emirates
393
+ '972' => fixed(2), # Israel (State of)
394
+ '973' => fixed(2), # Bahrain (Kingdom of)
395
+ '974' => fixed(2), # Qatar (State of)
396
+ '975' => fixed(2), # Bhutan (Kingdom of)
397
+ '976' => fixed(2), # Mongolia
398
+ '977' => fixed(2), # Nepal
399
+ '978' => fixed(2), # -
400
+ '979' => fixed(2), # International Premium Rate Service (IPRS)
401
+
402
+ '990' => fixed(2), # Spare code
403
+ '991' => fixed(2), # Trial of a proposed new international telecommunication public correspondence service, shared code
404
+ '992' => fixed(2), # Tajikistan (Republic of)
405
+ '993' => fixed(2), # Turkmenistan
406
+ '994' => fixed(2), # Azerbaijani Republic
407
+ '995' => fixed(2), # Georgia
408
+ '996' => fixed(2), # Kyrgyz Republic
409
+ '997' => fixed(2), # Spare code
410
+ '998' => fixed(2), # Uzbekistan (Republic of)
411
+ '999' => fixed(2), # Reserved for possible future use within the Telecommunications for Disaster Relief (TDR) concept
412
+ }
413
+ }
414
+ end
415
+
416
+ end
417
+ end
@@ -0,0 +1,69 @@
1
+ # Austria uses a variable-length ndc code, thus we use a separate file to not let all_other.rb explode.
2
+ #
3
+ Phony::Countries::Austria = Phony::Country.configured :local_format => [10],
4
+ :local_special_format => [10],
5
+ :ndc_fallback_length => 4,
6
+ :ndc_mapping => {
7
+ :landline => [
8
+ '1', # Vienna
9
+ '57', # -
10
+ '59', # -
11
+ '89', # Routing Number
12
+ '316', # Graz
13
+ '501', # -
14
+ '502', # -
15
+ '503', # -
16
+ '504', # -
17
+ '505', # -
18
+ '506', # -
19
+ '507', # -
20
+ '508', # -
21
+ '509', # -
22
+ '512', # Innsbruck
23
+ '517', # -
24
+ '662', # Salzburg
25
+ '720', #
26
+ '732' # Linz
27
+ ],
28
+ :mobile => [
29
+ '67',
30
+ '68',
31
+ '644',
32
+ '650',
33
+ '651',
34
+ '652',
35
+ '653',
36
+ '655',
37
+ '657',
38
+ '659',
39
+ '660',
40
+ '661',
41
+ '663',
42
+ '664',
43
+ '665',
44
+ '666',
45
+ '667',
46
+ '668',
47
+ '669'
48
+ ],
49
+ :service => [
50
+ '710',
51
+ '711',
52
+ '718',
53
+ '730',
54
+ '740',
55
+ '780',
56
+ '800',
57
+ '802',
58
+ '804',
59
+ '810',
60
+ '820',
61
+ '821',
62
+ '828',
63
+ '900',
64
+ '901',
65
+ '930',
66
+ '931',
67
+ '939'
68
+ ]
69
+ }