phony 2.17.0 → 2.20.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.textile +34 -6
  3. data/lib/phony/config.rb +91 -0
  4. data/lib/phony/countries/argentina.rb +355 -0
  5. data/lib/phony/countries/austria.rb +4 -2
  6. data/lib/phony/countries/bangladesh.rb +2 -0
  7. data/lib/phony/countries/belarus.rb +2 -0
  8. data/lib/phony/countries/brazil.rb +4 -2
  9. data/lib/phony/countries/cambodia.rb +3 -5
  10. data/lib/phony/countries/china.rb +7 -2
  11. data/lib/phony/countries/croatia.rb +2 -0
  12. data/lib/phony/countries/georgia.rb +2 -0
  13. data/lib/phony/countries/germany.rb +5 -2
  14. data/lib/phony/countries/guinea.rb +8 -5
  15. data/lib/phony/countries/india.rb +2 -0
  16. data/lib/phony/countries/indonesia.rb +2 -0
  17. data/lib/phony/countries/ireland.rb +27 -23
  18. data/lib/phony/countries/italy.rb +41 -18
  19. data/lib/phony/countries/japan.rb +60 -8
  20. data/lib/phony/countries/kyrgyzstan.rb +2 -0
  21. data/lib/phony/countries/latvia.rb +2 -0
  22. data/lib/phony/countries/libya.rb +3 -1
  23. data/lib/phony/countries/malaysia.rb +2 -0
  24. data/lib/phony/countries/moldova.rb +2 -0
  25. data/lib/phony/countries/montenegro.rb +2 -0
  26. data/lib/phony/countries/myanmar.rb +2 -0
  27. data/lib/phony/countries/namibia.rb +2 -0
  28. data/lib/phony/countries/nepal.rb +2 -0
  29. data/lib/phony/countries/netherlands.rb +2 -0
  30. data/lib/phony/countries/pakistan.rb +2 -0
  31. data/lib/phony/countries/paraguay.rb +2 -0
  32. data/lib/phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb +2 -0
  33. data/lib/phony/countries/saudi_arabia.rb +2 -0
  34. data/lib/phony/countries/serbia.rb +7 -1
  35. data/lib/phony/countries/somalia.rb +2 -0
  36. data/lib/phony/countries/south_korea.rb +7 -2
  37. data/lib/phony/countries/sweden.rb +2 -0
  38. data/lib/phony/countries/taiwan.rb +3 -0
  39. data/lib/phony/countries/tajikistan.rb +2 -0
  40. data/lib/phony/countries/turkmenistan.rb +2 -0
  41. data/lib/phony/countries/ukraine.rb +2 -0
  42. data/lib/phony/countries/united_kingdom.rb +5 -2
  43. data/lib/phony/countries/uruguay.rb +2 -0
  44. data/lib/phony/countries/vietnam.rb +7 -1
  45. data/lib/phony/countries/zimbabwe.rb +2 -0
  46. data/lib/phony/countries.rb +108 -65
  47. data/lib/phony/country.rb +11 -3
  48. data/lib/phony/country_codes.rb +16 -3
  49. data/lib/phony/dsl.rb +5 -3
  50. data/lib/phony/local_splitters/fixed.rb +2 -0
  51. data/lib/phony/national_code.rb +1 -1
  52. data/lib/phony/national_splitters/none.rb +1 -3
  53. data/lib/phony/trunk_code.rb +5 -5
  54. data/lib/phony.rb +62 -57
  55. data/spec/functional/config_spec.rb +44 -0
  56. data/spec/functional/plausibility_spec.rb +104 -19
  57. data/spec/lib/phony/countries_spec.rb +107 -35
  58. data/spec/lib/phony/country_codes_spec.rb +82 -58
  59. data/spec/lib/phony/country_spec.rb +29 -9
  60. data/spec/lib/phony/dsl_spec.rb +7 -3
  61. data/spec/lib/phony/local_splitters/regex_spec.rb +19 -15
  62. data/spec/lib/phony/national_code_spec.rb +15 -45
  63. data/spec/lib/phony/national_splitters/fixed_spec.rb +12 -16
  64. data/spec/lib/phony/national_splitters/none_spec.rb +3 -3
  65. data/spec/lib/phony/national_splitters/variable_spec.rb +9 -13
  66. data/spec/lib/phony/trunk_code_spec.rb +85 -0
  67. data/spec/lib/phony/vanity_spec.rb +4 -4
  68. metadata +23 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 719cbc1250612306ada5780c84781e64894b4ff8ff7c3681242a53237d1fee8c
4
- data.tar.gz: 6ffdf26bf946e357021bcac364f4dad7f68871a01ee887a81e9783051671b3a4
3
+ metadata.gz: b309483112eea98930ed42b246d6df922d06e268212e696aa23c28035956f65c
4
+ data.tar.gz: 1ee4fbc7968e7bbc3d90ac062635c2cc810d9aa3890103aeeb03fd13dbddedc5
5
5
  SHA512:
6
- metadata.gz: f45108af8f560d29fbf657b7635614ab852116eb14e51117ad2338c0cacb66c28634235008adce46b26e6d9094e457ee7a2087e24c6869d0e17fbfd00e0a546e
7
- data.tar.gz: 2d6d7b7ba0faf7f1e9a323e6d39a6e4b8f0c674b42686d17deaa865d7f3bc44cc5ddc4580bbc7fae15f2b0649512fa14325630f6b8f6abe98cf125fa7e6c3005
6
+ metadata.gz: 76d9ad6a66e4df3eecdd12338ac140f3f93eb8fde71975c01035373f1f4074a9590d32251f50ef0207949f23561cc9b72ae83b1d3960148c23cb3156c9c172ad
7
+ data.tar.gz: a4e5c31d362c9afbca54e4fd7248569b008d405ea4b2ea52891f3f4b84cc01514f982e79a80a619886cb57f5c142c55de9342f8c1af4a7df1f9893ea1182dfd7
data/README.textile CHANGED
@@ -5,16 +5,16 @@
5
5
 
6
6
  h1. Phony
7
7
 
8
- Disclaimer: Phony works with international numbers only, such as @+61 412 345 678@!
8
+ Disclaimer: Phony works with international numbers only, such as @61 412 345 678@!
9
9
 
10
10
  The (admittedly crazy) goal of this Gem is to be able to normalize/format/split all phone numbers in the world.
11
11
 
12
12
  Used in: "airbnb.com":http://airbnb.com, "socialcam.com":http://socialcam.com, "zendesk.com":http://www.zendesk.com/ (and many, many others).
13
13
 
14
- h2. Runtime Memory Usage
14
+ h2(#memory). Runtime Memory Usage
15
15
 
16
- According to "memory_profiler":https://github.com/SamSaffron/memory_profiler, the Phony gem uses roughly 2 MBs of memory per Ruby process.
17
- Usage was generated using: @ruby -e 'require "memory_profiler"; MemoryProfiler.report(allow_files: "phony"){ require "phony" }.pretty_print'@
16
+ According to "memory_profiler":https://github.com/SamSaffron/memory_profiler, the Phony gem uses roughly 1MB of memory per Ruby process.
17
+ Usage was generated using (look for @Total retained@): @ruby -e 'require "memory_profiler"; MemoryProfiler.report(allow_files: "phony"){ require "phony" }.pretty_print'@
18
18
 
19
19
  h2. Description
20
20
 
@@ -27,7 +27,7 @@ E164 numbers are international numbers with a country dial prefix, usually an ar
27
27
 
28
28
  It currently handles the countries listed at the end of this README.
29
29
 
30
- It is covered by roughly 2,000 tests (January 2016).
30
+ It is covered by roughly 2,250 tests that run in 2 seconds (April 2019).
31
31
  If it doesn't work, please "enter an issue":http://github.com/floere/phony/issues or better, fork and "send a pull request":http://github.com/floere/phony/pulls.
32
32
 
33
33
  h2. Installation
@@ -78,9 +78,37 @@ NB If a country does not have an NDC, @#split@ will return @false@ in the NDC po
78
78
 
79
79
  @Phony.split('4512121212').assert == ['45', false, '12', '12', '12', '12']@
80
80
 
81
+ h3(#loading). Loading only a country subset (Phony 2.18.0+).
82
+
83
+ Use this in case you'd like to save "memory":#memory that is used by Phony's CC rules.
84
+
85
+ "Phony::Config.load docs":./qed/config.md
86
+
87
+ First, @require 'phony/config'@.
88
+ Then, one of the following, which will load the rest of Phony.
89
+
90
+ Load only these CCs:
91
+ @Phony::Config.load(only: ['41', '44'])@
92
+
93
+ Loads everything except these CCs:
94
+ @Phony::Config.load(except: ['41', '44'])@
95
+
96
+ Convenience form of @only@:
97
+ @Phony::Config.load('41', '44')@
98
+
99
+ Each of these loads the rest of Phony.
100
+
101
+ Memory usage can be checked using (look for @Total retained@):
102
+ @ruby -e 'require "memory_profiler"; MemoryProfiler.report(allow_files: "phony"){ require "phony/config"; Phony::Config.load("1") }.pretty_print'@
103
+ For example, when just loading the NANP CC, the retained memory usage is ~63kB.
104
+
81
105
  h2. List of Handled Countries
82
106
 
83
- Mildly unmaintained list: Abhas, Afghan, Algerian, Argentina, Austrian, Australian, Azerbaijani, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, El Salvadorian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Iran, Irish, Israel, Italian, Kazakh, Liberian, Lithuanian, Luxembourgian, Malaysian, Malta, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, Vietnamese, and Zambian numbers.
107
+ Mildly unmaintained list: Abhas, Afghan, Algerian, Argentina, Austrian, Australian, Azerbaijani, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, El Salvadorian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Iran, Irish, Israel, Italian, Japanese, Kazakh, Liberian, Lithuanian, Luxembourgian, Malaysian, Malta, Mauritian, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, Vietnamese, and Zambian numbers.
108
+
109
+ h2. Proud Sponsors
110
+
111
+ * Renuo AG (July 22 –): "Github":https://github.com/renuo, "Homepage":https://www.renuo.ch
84
112
 
85
113
  h2. License
86
114
 
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phony
4
+
5
+ # Add config.
6
+ class << self
7
+ attr_writer :config
8
+
9
+ def config
10
+ # Default config includes all CCs.
11
+ @config ||= Config.new([], [])
12
+ end
13
+ end
14
+
15
+ # The Config class is only used to configure Phony and to load specific
16
+ # subsets of CCs.
17
+ #
18
+ class Config
19
+
20
+ attr_reader :included_ccs, :excluded_ccs
21
+
22
+ def initialize included_ccs, excluded_ccs
23
+ @included_ccs = included_ccs || []
24
+ @excluded_ccs = excluded_ccs || []
25
+ end
26
+
27
+ def load? cc
28
+ return false if has_excluded? && excluded_ccs.include?(cc)
29
+
30
+ if has_included?
31
+ # We have to check the included_ccs, otherwise false.
32
+ return true if included_ccs.include?(cc)
33
+
34
+ false
35
+ else
36
+ # It's not in excluded and no included was given.
37
+ true
38
+ end
39
+ end
40
+ def has_included?
41
+ !included_ccs.empty?
42
+ end
43
+ def has_excluded?
44
+ !excluded_ccs.empty?
45
+ end
46
+
47
+ # Use as follows:
48
+ #
49
+ # require 'phony/config'
50
+ #
51
+ # # Load only these:
52
+ # Phony::Config.load(only: ['41', '44'])
53
+ # # or all except these:
54
+ # Phony::Config.load(except: ['41', '44'])
55
+ # # or "only", in short form.
56
+ # Phony::Config.load('41', '44')
57
+ # # or even shorter form:
58
+ # Phony::Config.load(41, 44)
59
+ #
60
+ def self.load *options
61
+ # Extract options.
62
+ last = options.last
63
+ only, except = if last.respond_to?(:to_hash)
64
+ # We have the explicit form.
65
+ [last[:only], last[:except]]
66
+ elsif options.respond_to?(:to_ary)
67
+ # We have the convenience short forms.
68
+ [options, []]
69
+ end
70
+
71
+ # Set defaults.
72
+ only, except = [only || [], except || []]
73
+ # Convert to expected format if possible.
74
+ only, except = [only.map(&:to_s), except.map(&:to_s)]
75
+
76
+ # Check params.
77
+ raise "Params given to Phony::Config.load must be Array-like. The one given was: #{only}" unless only.respond_to?(:to_ary)
78
+ raise "Params given to Phony::Config.load must be Array-like. The one given was: #{except}" unless except.respond_to?(:to_ary)
79
+
80
+ # Configure Phony.
81
+ Phony.config = new(only, except)
82
+
83
+ # Load phony.
84
+ Kernel.load File.expand_path('../../phony.rb', __FILE__)
85
+
86
+ # Return the stored config data.
87
+ Phony.config
88
+ end
89
+
90
+ end
91
+ end
@@ -0,0 +1,355 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Argentinian numbers are all ten digits long.
4
+ # Information taken from:
5
+ # https://www.enacom.gob.ar/multimedia/normativas/1997/Resolucion%2046_97.pdf
6
+ # http://www.wtng.info/wtng-54-ar.html
7
+ # https://en.wikipedia.org/wiki/Telephone_numbers_in_Argentina
8
+ # Area codes collected from https://www.enacom.gob.ar/indicativos-interurbanos_p366 (06/27/19)
9
+
10
+
11
+ # Landline
12
+ area_codes_2digits = [
13
+ '11',
14
+ ]
15
+
16
+ area_codes_3digits = [
17
+ '220',
18
+ '221',
19
+ '223',
20
+ '230',
21
+ '236',
22
+ '237',
23
+ '249',
24
+ '260',
25
+ '261',
26
+ '263',
27
+ '264',
28
+ '266',
29
+ '280',
30
+ '291',
31
+ '294',
32
+ '297',
33
+ '298',
34
+ '299',
35
+ '336',
36
+ '341',
37
+ '342',
38
+ '343',
39
+ '345',
40
+ '348',
41
+ '351',
42
+ '353',
43
+ '358',
44
+ '362',
45
+ '364',
46
+ '370',
47
+ '376',
48
+ '379',
49
+ '380',
50
+ '381',
51
+ '383',
52
+ '385',
53
+ '387',
54
+ '388',
55
+ ]
56
+
57
+ area_codes_4digits = [
58
+ '2202',
59
+ '2221',
60
+ '2223',
61
+ '2224',
62
+ '2225',
63
+ '2226',
64
+ '2227',
65
+ '2229',
66
+ '2241',
67
+ '2242',
68
+ '2243',
69
+ '2244',
70
+ '2245',
71
+ '2246',
72
+ '2252',
73
+ '2254',
74
+ '2255',
75
+ '2257',
76
+ '2261',
77
+ '2262',
78
+ '2264',
79
+ '2265',
80
+ '2266',
81
+ '2267',
82
+ '2268',
83
+ '2271',
84
+ '2272',
85
+ '2273',
86
+ '2274',
87
+ '2281',
88
+ '2283',
89
+ '2284',
90
+ '2285',
91
+ '2286',
92
+ '2291',
93
+ '2292',
94
+ '2296',
95
+ '2297',
96
+ '2302',
97
+ '2314',
98
+ '2316',
99
+ '2317',
100
+ '2320',
101
+ '2323',
102
+ '2324',
103
+ '2325',
104
+ '2326',
105
+ '2331',
106
+ '2333',
107
+ '2334',
108
+ '2335',
109
+ '2336',
110
+ '2337',
111
+ '2338',
112
+ '2342',
113
+ '2343',
114
+ '2344',
115
+ '2345',
116
+ '2346',
117
+ '2352',
118
+ '2353',
119
+ '2354',
120
+ '2355',
121
+ '2356',
122
+ '2357',
123
+ '2358',
124
+ '2392',
125
+ '2393',
126
+ '2394',
127
+ '2395',
128
+ '2396',
129
+ '2473',
130
+ '2474',
131
+ '2475',
132
+ '2477',
133
+ '2478',
134
+ '2622',
135
+ '2624',
136
+ '2625',
137
+ '2626',
138
+ '2646',
139
+ '2647',
140
+ '2648',
141
+ '2651',
142
+ '2655',
143
+ '2656',
144
+ '2657',
145
+ '2658',
146
+ '2901',
147
+ '2902',
148
+ '2903',
149
+ '2920',
150
+ '2921',
151
+ '2922',
152
+ '2923',
153
+ '2924',
154
+ '2925',
155
+ '2926',
156
+ '2927',
157
+ '2928',
158
+ '2929',
159
+ '2931',
160
+ '2932',
161
+ '2933',
162
+ '2934',
163
+ '2935',
164
+ '2936',
165
+ '2940',
166
+ '2942',
167
+ '2945',
168
+ '2946',
169
+ '2948',
170
+ '2952',
171
+ '2953',
172
+ '2954',
173
+ '2962',
174
+ '2963',
175
+ '2964',
176
+ '2966',
177
+ '2972',
178
+ '2982',
179
+ '2983',
180
+ '3327',
181
+ '3329',
182
+ '3382',
183
+ '3385',
184
+ '3387',
185
+ '3388',
186
+ '3400',
187
+ '3401',
188
+ '3402',
189
+ '3404',
190
+ '3405',
191
+ '3406',
192
+ '3407',
193
+ '3408',
194
+ '3409',
195
+ '3435',
196
+ '3436',
197
+ '3437',
198
+ '3438',
199
+ '3442',
200
+ '3444',
201
+ '3445',
202
+ '3446',
203
+ '3447',
204
+ '3454',
205
+ '3455',
206
+ '3456',
207
+ '3458',
208
+ '3460',
209
+ '3462',
210
+ '3463',
211
+ '3464',
212
+ '3465',
213
+ '3466',
214
+ '3467',
215
+ '3468',
216
+ '3469',
217
+ '3471',
218
+ '3472',
219
+ '3476',
220
+ '3482',
221
+ '3483',
222
+ '3487',
223
+ '3489',
224
+ '3491',
225
+ '3492',
226
+ '3493',
227
+ '3496',
228
+ '3497',
229
+ '3498',
230
+ '3521',
231
+ '3522',
232
+ '3524',
233
+ '3525',
234
+ '3532',
235
+ '3533',
236
+ '3537',
237
+ '3541',
238
+ '3542',
239
+ '3543',
240
+ '3544',
241
+ '3546',
242
+ '3547',
243
+ '3548',
244
+ '3549',
245
+ '3562',
246
+ '3563',
247
+ '3564',
248
+ '3571',
249
+ '3572',
250
+ '3573',
251
+ '3574',
252
+ '3575',
253
+ '3576',
254
+ '3582',
255
+ '3583',
256
+ '3584',
257
+ '3585',
258
+ '3711',
259
+ '3715',
260
+ '3716',
261
+ '3718',
262
+ '3721',
263
+ '3725',
264
+ '3731',
265
+ '3734',
266
+ '3735',
267
+ '3741',
268
+ '3743',
269
+ '3751',
270
+ '3754',
271
+ '3755',
272
+ '3756',
273
+ '3757',
274
+ '3758',
275
+ '3772',
276
+ '3773',
277
+ '3774',
278
+ '3775',
279
+ '3777',
280
+ '3781',
281
+ '3782',
282
+ '3786',
283
+ '3821',
284
+ '3825',
285
+ '3826',
286
+ '3827',
287
+ '3832',
288
+ '3835',
289
+ '3837',
290
+ '3838',
291
+ '3841',
292
+ '3843',
293
+ '3844',
294
+ '3845',
295
+ '3846',
296
+ '3854',
297
+ '3855',
298
+ '3856',
299
+ '3857',
300
+ '3858',
301
+ '3861',
302
+ '3862',
303
+ '3863',
304
+ '3865',
305
+ '3867',
306
+ '3868',
307
+ '3869',
308
+ '3873',
309
+ '3876',
310
+ '3877',
311
+ '3878',
312
+ '3885',
313
+ '3886',
314
+ '3887',
315
+ '3888',
316
+ '3891',
317
+ '3892',
318
+ '3894',
319
+ ]
320
+
321
+ # Mobile
322
+ # Mobile phone numbers in Argentina are assigned the same geographic area codes as fixed lines,
323
+ # according to the subscriber's choice or residence, and can be 6, 7 or 8 digits long, just as
324
+ # landline numbers are. The difference with landline numbers is that a prefix 15, never used for
325
+ # landlines, must be dialed.
326
+
327
+
328
+
329
+ # International: +54 + 9 + area code + subscriber number (without '15' prefix)
330
+ # Domestic: area code + 15 + subscriber number
331
+ # Mobile numbers in Argentina may be listed as 15-xxxxxxx. However, the leading '15'
332
+ # is a domestic prefix which must be omitted when calling these from outside Argentina,
333
+ # with the xxxxxxx being the actual subscriber number portion.
334
+
335
+ # Non-geographic numbers 0ppp-nnn-nnnn
336
+ special_numbers = [
337
+ '800', # toll-free telephone numbers
338
+ '810', # calls from any area chargeable at local rate
339
+ '822', # toll-free numbers used for calling card access
340
+ '600', # premium-rate telephone numbers
341
+ '609', # premium, fixed-rate gaming numbers
342
+ '610', # dial-up Internet access numbers, usually cheaper than a local call, less frequently used as dial-up Internet access decreased
343
+ '605', # premium-rate telephone numbers for charity donations
344
+ ]
345
+
346
+ Phony.define do
347
+ country '54', trunk('0') |
348
+ one_of(area_codes_4digits) >> split(2, 4) | # landline
349
+ one_of(area_codes_3digits) >> split(3, 4) | # landline
350
+ one_of(area_codes_2digits) >> split(4, 4) | # landline
351
+ one_of(area_codes_2digits.map{|x| "9#{x}" }) >> split(4, 4) | # mobile
352
+ one_of(area_codes_3digits.map{|x| "9#{x}" }) >> split(3, 4) | # mobile
353
+ one_of(area_codes_4digits.map{|x| "9#{x}" }) >> split(2, 4) | # mobile
354
+ one_of(special_numbers) >> split(3, 4)
355
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Austria uses a variable-length ndc code, thus we use a separate file to not let all_other.rb explode.
2
4
  #
3
5
  ndcs = [
@@ -83,7 +85,7 @@ service = [
83
85
  '939'
84
86
  ]
85
87
 
86
- # https://www.rtr.at/en/tk/E129/2312_Austrian_Numbering_Plan_2011-03-30.pdf
88
+ # https://www.rtr.at/en/tk/E129/Austrian_Numbering_Plan_2011-03-30.pdf
87
89
  #
88
90
  # TODO Add more details.
89
91
  #
@@ -95,7 +97,7 @@ Phony.define do
95
97
  one_of('800') >> split(6..10) | # Free number length is 9..13
96
98
  one_of(corporate_2digit) >> split(3..11) | # Corporate number length is 5..13
97
99
  one_of(corporate) >> split(2..10) | # Corporate number length is 5..13
98
- one_of(ndcs) >> split(6..10) |
100
+ one_of(ndcs) >> split(5..10) |
99
101
  one_of('663') >> split(6..8) | # 6..8 digit mobile.
100
102
  one_of(mobile) >> split(4,3..9) |
101
103
  one_of(mobile_2digit) >> split(7..7) | # Separate as mobile contains 676 - 67 violates the prefix rule.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Bangladesh (People's Republic of)
2
4
  # https://www.numberingplans.com
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Belarus
2
4
  # http://www.eng.beltelecom.by/en/subscribers/phone-codes
3
5
  # https://www.numberingplans.com
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Brazilian phone numbers.
2
4
  #
3
5
  #
4
6
  # NDC Reference
5
- # http://www.anatel.gov.br/hotsites/CodigosNacionaisLocalidade/TelefoneCelular-CodigosDeArea.htm
7
+ # https://www.gov.br/anatel/pt-br/regulado/numeracao/plano-de-numeracao-brasileiro
6
8
 
7
9
  # 11 #Sao Paulo
8
10
  # 12 #Sao Paulo
@@ -97,7 +99,7 @@ special_numbers_4 = %w{ 3003 4003 4004 4020 }
97
99
  Phony.define do
98
100
  country '55',
99
101
  match(/^#{ndcs}9\d{8}$/) >> split(5,4) |
100
- match(/^#{ndcs}\d{8}$/) >> split(4,4) |
102
+ match(/^#{ndcs}[2-5]\d{7}$/) >> split(4,4) |
101
103
  one_of(special_numbers_3_4) >> split(3,4) |
102
104
  one_of(special_numbers_4) >> split(4) |
103
105
  one_of(service) >> split(3) |
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Cambodia (Kingdom of)
2
4
  # http://en.wikipedia.org/wiki/Telecommunications_in_Cambodia#Mobile_networks
3
5
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Cambodia
@@ -69,6 +71,7 @@ six_digit_extended_range_mobile_prefixes = [
69
71
  ]
70
72
 
71
73
  seven_digit_mobile_prefixes = [
74
+ '18', # Seatel
72
75
  '31', # Metfone
73
76
  '38', # CooTel
74
77
  '39', # EMAXX
@@ -83,10 +86,6 @@ variable_length_extended_range_mobile_prefixes = [
83
86
  '12' # Mobitel
84
87
  ]
85
88
 
86
- mobile_prefixes_with_variable_length = [
87
- '18' # Seatel
88
- ]
89
-
90
89
  six_digit_total_single_digit_fixed_line_prefixes = [
91
90
  '2', # Telecom Cambodia
92
91
  '3', # Mobitel
@@ -124,7 +123,6 @@ seven_digit_total_double_digit_fixed_line_prefixes = [
124
123
 
125
124
  Phony.define do
126
125
  country '855', trunk('0', :normalize => true) |
127
- one_of(mobile_prefixes_with_variable_length) >> matched_split(/^9/ => [3, 4], /^[2-8]/ => [3, 3]) |
128
126
  one_of(variable_length_extended_range_mobile_prefixes) >> matched_split(/^1/ => [3, 4], /^[2-9]/ => [3, 3]) |
129
127
  one_of(six_digit_mobile_prefixes) >> matched_split(/^[2-9]/ => [3, 3]) |
130
128
  one_of(six_digit_extended_range_mobile_prefixes) >> matched_split(/^[1-9]/ => [3, 3]) |
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Chinese phone numbers.
2
4
  #
3
5
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_China
@@ -17,7 +19,7 @@ ndcs = [
17
19
  '28', # Chengdu
18
20
  '29', # Xi'an
19
21
  ]
20
- mobile = %w{ 130 131 132 133 134 135 136 137 138 139 145 150 151 152 153 155 156 157 158 159 185 186 187 188 189 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 }
22
+ mobile = %w{ 130 131 132 133 134 135 136 137 138 139 145 146 147 148 149 150 151 152 153 155 156 157 158 159 162 165 166 167 170 171 172 173 174 175 176 177 178 180 181 182 183 184 185 186 187 188 189 190 191 192 193 195 196 197 198 199 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 }
21
23
  service = %w{ 110 114 119 120 122 999 } # Probably not exhaustive. TODO Look at http://www.eoc.com.cn/?action-viewnews-itemid-11493.
22
24
 
23
25
  Phony.define do
@@ -26,5 +28,8 @@ Phony.define do
26
28
  one_of(service) >> split(8) |
27
29
  one_of(mobile) >> split(4,4) |
28
30
  one_of(ndcs) >> split(4,4) |
29
- fixed(3) >> split(4,4)
31
+ fixed(3) >> matched_split(
32
+ /\A\d{7}\z/ => [3,4],
33
+ /\A\d{8}\z/ => [4,4]
34
+ )
30
35
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Croatia
2
4
  #
3
5
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Croatia
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Georgia
2
4
  # https://www.numberingplans.com/?page=dialling&sub=areacodes
3
5
  # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=GE
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Germany uses a variable-length ndc code, thus we use a separate file to not let countries.rb explode.
2
4
  #
3
5
  # Note: Germany uses a variable ndc format from length 2 to 5.
@@ -4019,8 +4021,9 @@ mobile_4digits = [
4019
4021
  '1520', # Vodafone
4020
4022
  '1521', # Lycamobile
4021
4023
  '1522', # Vodafone
4024
+ '1523', # Vodafone
4022
4025
  '1570', # vistream
4023
- '1527', # E-Plus
4026
+ '1577', # E-Plus
4024
4027
  '1672', # Dolphin Telecom
4025
4028
  ]
4026
4029
 
@@ -4087,7 +4090,7 @@ Phony.define do
4087
4090
  one_of(*service) >> split(3,1..9) |
4088
4091
  one_of(*mobile_4digits) >> split(3,4) |
4089
4092
  one_of(*mobile_3digits) >> split(4,3..4) |
4090
- one_of(*ndcs2) >> split(3,2..10) |
4093
+ one_of(*ndcs2) >> split(3,1..10) |
4091
4094
  one_of(*ndcs3) >> split(3,1..9) |
4092
4095
  one_of(*ndcs4) >> split(3,0..8) |
4093
4096
  fixed(5) >> split(3,0..7)