phony 2.17.1 → 2.18.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.textile +29 -5
  3. data/lib/phony.rb +62 -57
  4. data/lib/phony/config.rb +91 -0
  5. data/lib/phony/countries.rb +8 -13
  6. data/lib/phony/countries/argentina.rb +355 -0
  7. data/lib/phony/countries/austria.rb +2 -0
  8. data/lib/phony/countries/bangladesh.rb +2 -0
  9. data/lib/phony/countries/belarus.rb +2 -0
  10. data/lib/phony/countries/brazil.rb +2 -0
  11. data/lib/phony/countries/cambodia.rb +2 -0
  12. data/lib/phony/countries/china.rb +2 -0
  13. data/lib/phony/countries/croatia.rb +2 -0
  14. data/lib/phony/countries/georgia.rb +2 -0
  15. data/lib/phony/countries/germany.rb +4 -1
  16. data/lib/phony/countries/guinea.rb +8 -5
  17. data/lib/phony/countries/india.rb +2 -0
  18. data/lib/phony/countries/indonesia.rb +2 -0
  19. data/lib/phony/countries/ireland.rb +25 -23
  20. data/lib/phony/countries/italy.rb +6 -1
  21. data/lib/phony/countries/japan.rb +2 -0
  22. data/lib/phony/countries/kyrgyzstan.rb +2 -0
  23. data/lib/phony/countries/latvia.rb +2 -0
  24. data/lib/phony/countries/libya.rb +2 -0
  25. data/lib/phony/countries/malaysia.rb +2 -0
  26. data/lib/phony/countries/moldova.rb +2 -0
  27. data/lib/phony/countries/montenegro.rb +2 -0
  28. data/lib/phony/countries/myanmar.rb +2 -0
  29. data/lib/phony/countries/namibia.rb +2 -0
  30. data/lib/phony/countries/nepal.rb +2 -0
  31. data/lib/phony/countries/netherlands.rb +2 -0
  32. data/lib/phony/countries/pakistan.rb +2 -0
  33. data/lib/phony/countries/paraguay.rb +2 -0
  34. data/lib/phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb +2 -0
  35. data/lib/phony/countries/saudi_arabia.rb +2 -0
  36. data/lib/phony/countries/serbia.rb +2 -0
  37. data/lib/phony/countries/somalia.rb +2 -0
  38. data/lib/phony/countries/south_korea.rb +7 -2
  39. data/lib/phony/countries/sweden.rb +2 -0
  40. data/lib/phony/countries/taiwan.rb +2 -0
  41. data/lib/phony/countries/tajikistan.rb +2 -0
  42. data/lib/phony/countries/turkmenistan.rb +2 -0
  43. data/lib/phony/countries/ukraine.rb +2 -0
  44. data/lib/phony/countries/united_kingdom.rb +5 -2
  45. data/lib/phony/countries/uruguay.rb +2 -0
  46. data/lib/phony/countries/vietnam.rb +3 -1
  47. data/lib/phony/countries/zimbabwe.rb +2 -0
  48. data/lib/phony/country.rb +3 -1
  49. data/lib/phony/country_codes.rb +1 -1
  50. data/lib/phony/dsl.rb +3 -1
  51. data/spec/functional/config_spec.rb +44 -0
  52. data/spec/functional/plausibility_spec.rb +6 -1
  53. data/spec/lib/phony/countries_spec.rb +18 -15
  54. data/spec/lib/phony/dsl_spec.rb +2 -2
  55. data/spec/lib/phony/local_splitters/regex_spec.rb +7 -0
  56. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36d6e16b362c50a1aa52f246d0b931d74b49cc3fd37e4fe9f5551db542a13cbe
4
- data.tar.gz: 87ac8a6da326707df10eac2055e74c05a6691a2d4fa47f18733cbb0bbc9b2111
3
+ metadata.gz: da81c89f8da18101dd1ad489ec5c6e7c66d6f3836058ba9b33f1eb4c02395ea2
4
+ data.tar.gz: a8fe8edd6e28d32ad7a0ea2ccdfb69c52897c2163f735b44b3e71e3fed7175ea
5
5
  SHA512:
6
- metadata.gz: 3a7a389f94b0c7ad4de95113cbfa391653c4fd9bb0e443ad89b1768a0378edb85c32d32659365792a1c86bb988ee8a698504ec141898fb46f707c76f341e440e
7
- data.tar.gz: 6077317c2e76ce1db698e02ae0936565b0e3be9b91096f50f49b0ff13a67514b2f6f82f5df7fb9274fa5e5f8f616f912b1abe5b009613e9fcec2ef21a45c1073
6
+ metadata.gz: b36455cfb130e3657e423b331f7a2978fd960be66af3834335506ce3c0a17690bb9775aefacbba1b5a617550e6f42f34b8e7a5c1c9cfb67d6a4d7e95cc2e17b0
7
+ data.tar.gz: 82d22fff926d5225418694fdcaa8553f621d529151f870d05530b74b11b9405b3164a67e7bc8bc14638610da58c14f0680939a7762243ec93f4d262f9d7b3b22
@@ -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,6 +78,30 @@ 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
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, 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.
@@ -1,70 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ # NOTE We use Kernel.load here, as it's possible to redefine Phony via Phony::Config.
4
+
1
5
  # Framework.
2
6
  #
3
- require File.expand_path '../phony/vanity', __FILE__
4
- require File.expand_path '../phony/local_splitters/fixed', __FILE__
5
- require File.expand_path '../phony/local_splitters/regex', __FILE__
6
- require File.expand_path '../phony/national_splitters/dsl', __FILE__
7
- require File.expand_path '../phony/national_splitters/fixed', __FILE__
8
- require File.expand_path '../phony/national_splitters/variable', __FILE__
9
- require File.expand_path '../phony/national_splitters/regex', __FILE__
10
- require File.expand_path '../phony/national_splitters/default', __FILE__
11
- require File.expand_path '../phony/national_splitters/none', __FILE__
12
- require File.expand_path '../phony/national_code', __FILE__
13
- require File.expand_path '../phony/country', __FILE__
14
- require File.expand_path '../phony/trunk_code', __FILE__
15
- require File.expand_path '../phony/country_codes', __FILE__
16
-
17
- require File.expand_path '../phony/dsl', __FILE__
7
+ load File.expand_path '../phony/config.rb', __FILE__
8
+ load File.expand_path '../phony/vanity.rb', __FILE__
9
+ load File.expand_path '../phony/local_splitters/fixed.rb', __FILE__
10
+ load File.expand_path '../phony/local_splitters/regex.rb', __FILE__
11
+ load File.expand_path '../phony/national_splitters/dsl.rb', __FILE__
12
+ load File.expand_path '../phony/national_splitters/fixed.rb', __FILE__
13
+ load File.expand_path '../phony/national_splitters/variable.rb', __FILE__
14
+ load File.expand_path '../phony/national_splitters/regex.rb', __FILE__
15
+ load File.expand_path '../phony/national_splitters/default.rb', __FILE__
16
+ load File.expand_path '../phony/national_splitters/none.rb', __FILE__
17
+ load File.expand_path '../phony/national_code.rb', __FILE__
18
+ load File.expand_path '../phony/country.rb', __FILE__
19
+ load File.expand_path '../phony/trunk_code.rb', __FILE__
20
+ load File.expand_path '../phony/country_codes.rb', __FILE__
21
+ load File.expand_path '../phony/dsl.rb', __FILE__
18
22
 
19
23
  # Countries.
20
24
  #
21
25
  # The ones that need more space to define.
22
26
  #
23
- require File.expand_path '../phony/countries/austria', __FILE__
24
- require File.expand_path '../phony/countries/bangladesh', __FILE__
25
- require File.expand_path '../phony/countries/belarus', __FILE__
26
- require File.expand_path '../phony/countries/brazil', __FILE__
27
- require File.expand_path '../phony/countries/cambodia', __FILE__
28
- require File.expand_path '../phony/countries/croatia', __FILE__
29
- require File.expand_path '../phony/countries/china', __FILE__
30
- require File.expand_path '../phony/countries/georgia', __FILE__
31
- require File.expand_path '../phony/countries/germany', __FILE__
32
- require File.expand_path '../phony/countries/guinea', __FILE__
33
- require File.expand_path '../phony/countries/india', __FILE__
34
- require File.expand_path '../phony/countries/indonesia', __FILE__
35
- require File.expand_path '../phony/countries/ireland', __FILE__
36
- require File.expand_path '../phony/countries/italy', __FILE__
37
- require File.expand_path '../phony/countries/japan', __FILE__
38
- require File.expand_path '../phony/countries/kyrgyzstan', __FILE__
39
- require File.expand_path '../phony/countries/latvia', __FILE__
40
- require File.expand_path '../phony/countries/libya', __FILE__
41
- require File.expand_path '../phony/countries/malaysia', __FILE__
42
- require File.expand_path '../phony/countries/moldova', __FILE__
43
- require File.expand_path '../phony/countries/montenegro', __FILE__
44
- require File.expand_path '../phony/countries/myanmar', __FILE__
45
- require File.expand_path '../phony/countries/namibia', __FILE__
46
- require File.expand_path '../phony/countries/nepal', __FILE__
47
- require File.expand_path '../phony/countries/netherlands', __FILE__
48
- require File.expand_path '../phony/countries/pakistan', __FILE__
49
- require File.expand_path '../phony/countries/paraguay', __FILE__
50
- require File.expand_path '../phony/countries/russia_kazakhstan_abkhasia_south_ossetia', __FILE__
51
- require File.expand_path '../phony/countries/saudi_arabia', __FILE__
52
- require File.expand_path '../phony/countries/serbia', __FILE__
53
- require File.expand_path '../phony/countries/somalia', __FILE__
54
- require File.expand_path '../phony/countries/south_korea', __FILE__
55
- require File.expand_path '../phony/countries/sweden', __FILE__
56
- require File.expand_path '../phony/countries/taiwan', __FILE__
57
- require File.expand_path '../phony/countries/tajikistan', __FILE__
58
- require File.expand_path '../phony/countries/turkmenistan', __FILE__
59
- require File.expand_path '../phony/countries/vietnam', __FILE__
60
- require File.expand_path '../phony/countries/ukraine', __FILE__
61
- require File.expand_path '../phony/countries/united_kingdom', __FILE__
62
- require File.expand_path '../phony/countries/uruguay', __FILE__
63
- require File.expand_path '../phony/countries/zimbabwe', __FILE__
27
+ load File.expand_path '../phony/countries/argentina.rb', __FILE__
28
+ load File.expand_path '../phony/countries/austria.rb', __FILE__
29
+ load File.expand_path '../phony/countries/bangladesh.rb', __FILE__
30
+ load File.expand_path '../phony/countries/belarus.rb', __FILE__
31
+ load File.expand_path '../phony/countries/brazil.rb', __FILE__
32
+ load File.expand_path '../phony/countries/cambodia.rb', __FILE__
33
+ load File.expand_path '../phony/countries/croatia.rb', __FILE__
34
+ load File.expand_path '../phony/countries/china.rb', __FILE__
35
+ load File.expand_path '../phony/countries/georgia.rb', __FILE__
36
+ load File.expand_path '../phony/countries/germany.rb', __FILE__
37
+ load File.expand_path '../phony/countries/guinea.rb', __FILE__
38
+ load File.expand_path '../phony/countries/india.rb', __FILE__
39
+ load File.expand_path '../phony/countries/indonesia.rb', __FILE__
40
+ load File.expand_path '../phony/countries/ireland.rb', __FILE__
41
+ load File.expand_path '../phony/countries/italy.rb', __FILE__
42
+ load File.expand_path '../phony/countries/japan.rb', __FILE__
43
+ load File.expand_path '../phony/countries/kyrgyzstan.rb', __FILE__
44
+ load File.expand_path '../phony/countries/latvia.rb', __FILE__
45
+ load File.expand_path '../phony/countries/libya.rb', __FILE__
46
+ load File.expand_path '../phony/countries/malaysia.rb', __FILE__
47
+ load File.expand_path '../phony/countries/moldova.rb', __FILE__
48
+ load File.expand_path '../phony/countries/montenegro.rb', __FILE__
49
+ load File.expand_path '../phony/countries/myanmar.rb', __FILE__
50
+ load File.expand_path '../phony/countries/namibia.rb', __FILE__
51
+ load File.expand_path '../phony/countries/nepal.rb', __FILE__
52
+ load File.expand_path '../phony/countries/netherlands.rb', __FILE__
53
+ load File.expand_path '../phony/countries/pakistan.rb', __FILE__
54
+ load File.expand_path '../phony/countries/paraguay.rb', __FILE__
55
+ load File.expand_path '../phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb', __FILE__
56
+ load File.expand_path '../phony/countries/saudi_arabia.rb', __FILE__
57
+ load File.expand_path '../phony/countries/serbia.rb', __FILE__
58
+ load File.expand_path '../phony/countries/somalia.rb', __FILE__
59
+ load File.expand_path '../phony/countries/south_korea.rb', __FILE__
60
+ load File.expand_path '../phony/countries/sweden.rb', __FILE__
61
+ load File.expand_path '../phony/countries/taiwan.rb', __FILE__
62
+ load File.expand_path '../phony/countries/tajikistan.rb', __FILE__
63
+ load File.expand_path '../phony/countries/turkmenistan.rb', __FILE__
64
+ load File.expand_path '../phony/countries/vietnam.rb', __FILE__
65
+ load File.expand_path '../phony/countries/ukraine.rb', __FILE__
66
+ load File.expand_path '../phony/countries/united_kingdom.rb', __FILE__
67
+ load File.expand_path '../phony/countries/uruguay.rb', __FILE__
68
+ load File.expand_path '../phony/countries/zimbabwe.rb', __FILE__
64
69
 
65
70
  # All other countries.
66
71
  #
67
- require File.expand_path '../phony/countries', __FILE__
72
+ load File.expand_path '../phony/countries.rb', __FILE__
68
73
 
69
74
  # Phony is the main module and is generally used to process
70
75
  # E164 phone numbers directly.
@@ -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
@@ -1,4 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+
2
4
  # All countries, ordered by country code.
3
5
  #
4
6
  # Definitions are in the format:
@@ -67,7 +69,7 @@ Phony.define do
67
69
  country '20', one_of('800') >> split(7..7) | # Egypt toll free
68
70
  one_of('3') >> split(7..7) | # Alexandria
69
71
  one_of('2') >> split(8..8) | # Cairo/Giza
70
- one_of('10', '11', '12') >> split(8..8) | # the 3 mobile operators
72
+ one_of('10', '11', '12', '15') >> split(8..8) | # the 4 mobile operators
71
73
  fixed(2) >> split(7..7) # all the other 24 provinces
72
74
 
73
75
  # South Africa.
@@ -211,14 +213,7 @@ Phony.define do
211
213
  fixed(3) >> split(7) # 3-digit NDCs
212
214
 
213
215
  # Argentine Republic.
214
- #
215
- country '54',
216
- one_of('11', '911') >> split(4,4) | # Fixed & Mobile
217
- match(/^(22[0137]|237|26[14]|29[179]|34[1235]|35[138]|38[1578])/) >> split(3,4) | # Fixed
218
- match(/^(922[0137]|9237|926[14]|929[179]|934[1235]|935[138]|938[1578])/) >> split(3,4) | # Mobile
219
- match(/^(9\d{4})/) >> split(2,4) | # Mobile
220
- match(/^([68]\d{2})/) >> split(3,4) | # Service
221
- fixed(4) >> split(2,4) # Fixed
216
+ # country '54' # argentina, see special file.
222
217
 
223
218
  # Brazil (Federative Republic of).
224
219
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Brazil
@@ -264,7 +259,7 @@ Phony.define do
264
259
  match(/\A(2)\d{10}\z/) >> split(10) |
265
260
  one_of('2') >> split(7) |
266
261
  # mobile
267
- match(/\A(9\d\d)\d{7}\z/) >> split(7) |
262
+ match(/\A([89]\d\d)\d{7}\z/) >> split(7) |
268
263
  match(/\A(9\d\d)\d+\z/) >> split(6) |
269
264
  #
270
265
  fixed(2) >> split(7)
@@ -1183,9 +1178,9 @@ Phony.define do
1183
1178
  # Israel (State of) (also works for numbers in Palestinian territories)
1184
1179
  country '972',
1185
1180
  trunk('0') |
1186
- one_of('1') >> split(3,3,3) | # special numbers
1187
- one_of('2', '3', '4', '8', '9') >> split(3,4) | # 1 digit ndc
1188
- match(/^(5[023456789]|7[23467])\d+$/) >> split(3,4) # 2 digit ndc
1181
+ one_of('1') >> split(3,3,3) | # special numbers
1182
+ one_of('2', '3', '4', '8', '9') >> split(3,4) | # 1 digit ndc
1183
+ match(/^(5[012345689]|7[234679])\d+$/) >> split(3,4) # 2 digit ndc
1189
1184
 
1190
1185
  country '973', none >> split(4,4..4) # Bahrain (Kingdom of) http://www.itu.int/oth/T0202000011/en
1191
1186
 
@@ -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, 5) | # mobile
352
+ one_of(area_codes_3digits.map{|x| "9#{x}" }) >> split(3, 5) | # mobile
353
+ one_of(area_codes_4digits.map{|x| "9#{x}" }) >> split(2, 5) | # mobile
354
+ one_of(special_numbers) >> split(3, 4)
355
+ end