phony 1.2.11 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/README.textile +1 -1
  2. data/lib/countries.rb +385 -0
  3. data/lib/phony.rb +11 -9
  4. data/lib/phony/countries.rb +1 -0
  5. data/lib/phony/countries/austria.rb +68 -67
  6. data/lib/phony/countries/belgium.rb +29 -57
  7. data/lib/phony/countries/chile.rb +5 -12
  8. data/lib/phony/countries/china.rb +21 -20
  9. data/lib/phony/countries/egypt.rb +12 -37
  10. data/lib/phony/countries/germany.rb +39 -36
  11. data/lib/phony/countries/greece.rb +21 -25
  12. data/lib/phony/countries/hungary.rb +6 -19
  13. data/lib/phony/countries/italy.rb +174 -152
  14. data/lib/phony/countries/malaysia.rb +17 -17
  15. data/lib/phony/countries/netherlands.rb +50 -52
  16. data/lib/phony/countries/romania.rb +28 -27
  17. data/lib/phony/countries/south_korea.rb +11 -11
  18. data/lib/phony/countries/sweden.rb +49 -49
  19. data/lib/phony/countries/united_kingdom.rb +4 -4
  20. data/lib/phony/country.rb +14 -80
  21. data/lib/phony/country_codes.rb +23 -3
  22. data/lib/phony/dsl.rb +78 -0
  23. data/lib/phony/national_code.rb +2 -5
  24. data/lib/phony/national_splitters/dsl.rb +20 -0
  25. data/lib/phony/national_splitters/fixed.rb +1 -1
  26. data/lib/phony/national_splitters/none.rb +1 -1
  27. data/lib/phony/national_splitters/regex.rb +49 -0
  28. data/lib/phony/national_splitters/variable.rb +6 -6
  29. data/lib/phony/vanity.rb +3 -0
  30. data/spec/lib/phony/country_codes_spec.rb +1 -1
  31. data/spec/lib/phony/country_spec.rb +12 -45
  32. data/spec/lib/phony/local_splitters/fixed_spec.rb +8 -0
  33. data/spec/lib/phony/national_code_spec.rb +13 -0
  34. data/spec/lib/phony/national_splitters/regex_spec.rb +23 -0
  35. data/spec/lib/phony/national_splitters/variable_spec.rb +2 -4
  36. data/spec/lib/phony_spec.rb +44 -4
  37. metadata +9 -21
  38. data/lib/phony/countries/all_other.rb +0 -455
  39. data/lib/phony/countries/norway.rb +0 -11
  40. data/lib/phony/countries/peru.rb +0 -19
  41. data/lib/phony/countries/portugal.rb +0 -16
  42. data/lib/phony/national_splitters/experimental.rb +0 -17
  43. data/spec/lib/phony/countries/austria_spec.rb +0 -24
  44. data/spec/lib/phony/countries/belgium_spec.rb +0 -33
  45. data/spec/lib/phony/countries/egypt_spec.rb +0 -18
  46. data/spec/lib/phony/countries/greece_spec.rb +0 -18
  47. data/spec/lib/phony/countries/portugal_spec.rb +0 -21
  48. data/spec/lib/phony/countries/switzerland_spec.rb +0 -18
  49. data/spec/lib/phony/countries/united_kingdom_spec.rb +0 -50
@@ -1,69 +1,70 @@
1
+ include Phony::DSL
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
- 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
- }
5
+ ndcs = [
6
+ '1', # Vienna
7
+ '57', # -
8
+ '59', # -
9
+ '89', # Routing Number
10
+ '316', # Graz
11
+ '501', # -
12
+ '502', # -
13
+ '503', # -
14
+ '504', # -
15
+ '505', # -
16
+ '506', # -
17
+ '507', # -
18
+ '508', # -
19
+ '509', # -
20
+ '512', # Innsbruck
21
+ '517', # -
22
+ '662', # Salzburg
23
+ '720', #
24
+ '732' # Linz
25
+ ]
26
+
27
+ mobile = [
28
+ '67',
29
+ '68',
30
+ '644',
31
+ '650',
32
+ '651',
33
+ '652',
34
+ '653',
35
+ '655',
36
+ '657',
37
+ '659',
38
+ '660',
39
+ '661',
40
+ '663',
41
+ '664',
42
+ '665',
43
+ '666',
44
+ '667',
45
+ '668',
46
+ '669'
47
+ ]
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
+
70
+ Phony::Countries::Austria = one_of(service + mobile + ndcs, :max_length => 4) >> split(10)
@@ -1,61 +1,33 @@
1
+ include Phony::DSL
2
+
1
3
  # Belgium uses a variable-length ndc code, thus we use a separate file to not let all_other.rb explode.
2
4
  #
3
5
  # Taken from: http://en.wikipedia.org/wiki/Telephone_numbers_in_Belgium
4
6
  #
5
- Phony::Countries::Belgium = Phony::Country.configured :local_format => [3, 5],
6
- :mobile_local_format => [6],
7
- :ndc_fallback_length => 2,
8
- :ndc_mapping => {
9
- :landline => [
10
- '2', # Brussels (Bruxelles/Brussel)
11
- '3', # Antwerpen (Antwerp), Sint-Niklaas
12
- '4', # Liège (Luik), Voeren (Fourons)
13
- '9', # Gent (Ghent/Gand)
14
- ],
15
- :mobile => [
16
- '470', # Mobistar
17
- '471', # Mobistar
18
- '472', # Mobistar
19
- '473', # Mobistar
20
- '474', # Mobistar
21
- '475', # Mobistar
22
- '476', # Mobistar
23
- '477', # Mobistar
24
- '478', # Mobistar
25
- '479', # Mobistar
26
- '480', # Base
27
- '481', # Base
28
- '482', # Base
29
- '483', # Base
30
- '484', # Base
31
- '485', # Base
32
- '486', # Base
33
- '487', # Base
34
- '488', # Base
35
- '489', # Base
36
- '490', # Proximus
37
- '491', # Proximus
38
- '492', # Proximus
39
- '493', # Proximus
40
- '494', # Proximus
41
- '495', # Proximus
42
- '496', # Proximus
43
- '497', # Proximus
44
- '498', # Proximus
45
- '499', # Proximus
46
- ],
47
- :service => [
48
- '70', # Specialty numbers, i.e. bus information or bank information
49
- '800', # Tollfree
50
- '900', # Premium
51
- '901', # Premium
52
- '902', # Premium
53
- '903', # Premium
54
- '904', # Premium
55
- '905', # Premium
56
- '906', # Premium
57
- '907', # Premium
58
- '908', # Premium
59
- '909' # Premium
60
- ]
61
- }
7
+ ndcs = [
8
+ '2', # Brussels (Bruxelles/Brussel)
9
+ '3', # Antwerpen (Antwerp), Sint-Niklaas
10
+ '4', # Liège (Luik), Voeren (Fourons)
11
+ '9', # Gent (Ghent/Gand)
12
+ ]
13
+
14
+ mobile_regex = /^(4[789]\d)\d{6}$/ # Mobistar, Base, Proximus
15
+
16
+ service = [
17
+ '70', # Specialty numbers, i.e. bus information or bank information
18
+ '800', # Tollfree
19
+ '900', # Premium
20
+ '901', # Premium
21
+ '902', # Premium
22
+ '903', # Premium
23
+ '904', # Premium
24
+ '905', # Premium
25
+ '906', # Premium
26
+ '907', # Premium
27
+ '908', # Premium
28
+ '909' # Premium
29
+ ]
30
+
31
+ Phony::Countries::Belgium = one_of(service) >> split(3,3) |
32
+ match(mobile_regex) >> split(6) |
33
+ one_of(ndcs, :max_length => 2) >> split(3,5)
@@ -6,15 +6,8 @@
6
6
  # Note: Totally unsure about this one, as I get contradicting infos (see links above).
7
7
  # As usual, best effort.
8
8
  #
9
- Phony::Countries::Chile = Phony::Country.configured :local_format => [8],
10
- :local_special_format => [3, 3],
11
- :ndc_fallback_length => 2,
12
- :ndc_mapping => {
13
- :landline => [
14
- '2', # Santiago
15
- ],
16
- :mobile => [
17
- '9',
18
- ],
19
- :service => %w{130 131 132 133 134 135 136 137 139 147 149}
20
- }
9
+ service = %w{130 131 132 133 134 135 136 137 139 147 149}
10
+
11
+ Phony::Countries::Chile = one_of(*service) >> split(3,3) |
12
+
13
+ one_of('2', '9', :max_length => 2) >> split(8) # Santiago (2) and mobile.
@@ -1,26 +1,27 @@
1
+ include Phony::DSL
2
+
1
3
  # Chinese phone numbers.
2
4
  #
3
5
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_China
4
6
  #
5
7
  # Note: Tibet partially uses 4-digit NDC codes. This is NOT YET reflected here.
6
8
  #
7
- Phony::Countries::China = Phony::Country.configured :local_format => [4, 4],
8
- :local_special_format => [8],
9
- :ndc_fallback_length => 3,
10
- :ndc_mapping => {
11
- :landline => [
12
- '10', # Beijing, TODO Confirm – is it 10 or 1?
13
- '20', # Guangzhou
14
- '21', # Shanghai
15
- '22', # Tianjin
16
- '23', # Chongquin
17
- '24', # Shenyang
18
- '25', # Nanjing
19
- '26', # Taipei, Taiwan - gotta be kidding, right?!
20
- '27', # Wuhan
21
- '28', # Chengdu
22
- '29', # Xi'an
23
- ],
24
- :mobile => %w{ 130 131 132 133 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 },
25
- :service => %w{ 110 114 119 120 122 999 } # Probably not exhaustive. TODO Look at http://www.eoc.com.cn/?action-viewnews-itemid-11493.
26
- }
9
+ ndcs = [
10
+ '10', # Beijing, TODO Confirm – is it 10 or 1?
11
+ '20', # Guangzhou
12
+ '21', # Shanghai
13
+ '22', # Tianjin
14
+ '23', # Chongquin
15
+ '24', # Shenyang
16
+ '25', # Nanjing
17
+ '26', # Taipei, Taiwan - gotta be kidding, right?!
18
+ '27', # Wuhan
19
+ '28', # Chengdu
20
+ '29', # Xi'an
21
+ ]
22
+ mobile = %w{ 130 131 132 133 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 }
23
+ service = %w{ 110 114 119 120 122 999 } # Probably not exhaustive. TODO Look at http://www.eoc.com.cn/?action-viewnews-itemid-11493.
24
+
25
+ Phony::Countries::China = one_of(service) >> split(8) |
26
+ one_of(mobile) >> split(4,4) |
27
+ one_of(ndcs, :max_length => 3) >> split(4,4)
@@ -1,42 +1,17 @@
1
+ include Phony::DSL
2
+
3
+ # TODO Move this into the country definitions.
4
+
1
5
  # Egyptian phone numbers.
2
6
  #
3
7
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Egypt
4
8
  #
5
- # TODO If the fallback length is 2, why do I list length 2 landlines?
9
+ ndcs = [
10
+ '2', # Cairo/Giza
11
+ '3', # Alexandria
12
+ ]
13
+
14
+ # TODO Change how one_of works. max_length should be optional.
6
15
  #
7
- Phony::Countries::Egypt = Phony::Country.configured :local_format => [8],
8
- :local_special_format => [7],
9
- :ndc_fallback_length => 2,
10
- :ndc_mapping => {
11
- :landline => [
12
- '2', # Cairo/Giza
13
- '3', # Alexandria
14
- '13', # Banha
15
- '15', # 10th of Ramadan
16
- '45', # Damanhur
17
- '46', # Marsa Matruh
18
- '47', # Kafer El Sheik
19
- '48', # Monufia
20
- '50', # Mansoura
21
- '55', # Zazazig
22
- '56', # Spare
23
- '57', # Damiette
24
- '62', # Suez
25
- '64', # Ismailia
26
- '65', # Red Sea
27
- '66', # Port Said
28
- '68', # El Arish
29
- '69', # El-Tor
30
- '82', # Beni Suef
31
- '84', # Fayoum
32
- '86', # Minia
33
- '88', # Assiout
34
- '92', # Wadi El Gehid
35
- '93', # Sohag
36
- '95', # Luxor
37
- '96', # Qunea
38
- '97', # Aswan
39
- ],
40
- :mobile => %w{10 11 12 14 16 17 18 19},
41
- :service => %w{800} # Not exhaustive.
42
- }
16
+ Phony::Countries::Egypt = one_of('800') >> split(7) |
17
+ one_of(ndcs, :max_length => 2) >> split(8)
@@ -1,12 +1,12 @@
1
+ include Phony::DSL
2
+
1
3
  # Germany uses a variable-length ndc code, thus we use a separate file to not let all_other.rb explode.
2
4
  #
3
5
  # Note: Germany uses a variable ndc format from length 2 to 5.
4
6
  #
5
- Phony::Countries::Germany = Phony::Country.configured :local_format => [3, 10],
6
- :local_special_format => [3, 10],
7
- :ndc_fallback_length => 5,
8
- :ndc_mapping => {
9
- :landline => ['10', # Call-By-Call
7
+
8
+ ndcs = [
9
+ '10', # Call-By-Call
10
10
  '11', # formerly Value Added Services
11
11
  '13', # Voting and Lottery Numbers
12
12
  '30', # Berlin
@@ -3990,36 +3990,36 @@ Phony::Countries::Germany = Phony::Country.configured :local_format => [3, 10],
3990
3990
  '9976',
3991
3991
  '9977',
3992
3992
  '9978',
3993
- ],
3994
- :mobile => [
3995
- '150', # Group3G/Quam
3996
- '151', # T-Mobile
3997
- '152', # Vodafone
3998
- '155', # E-Plus
3999
- '156', # Mobilcom
4000
- '157', # E-Plus
4001
- '159', # O2
4002
- '160', # T-Mobile
4003
- '161', # C-Netz
4004
- '162', # Vodafone
4005
- '163', # E-Plus
4006
- '164', # Cityruf
4007
- '165', # Quix
4008
- '166', # Telmi
4009
- '168', # Scall
4010
- '169', # Cityruf, Scall, Skyper (e*cityruf, e*message, e*skyper)
4011
- '170', # T-Mobile
4012
- '171', # T-Mobile
4013
- '172', # Vodafone
4014
- '173', # Vodafone
4015
- '174', # Vodafone
4016
- '175', # T-Mobile
4017
- '176', # O2 Germany
4018
- '177', # E-Plus
4019
- '178', # E-Plus
4020
- '179', # O2 Germany
4021
- ],
4022
- :service => [
3993
+ ]
3994
+ # mobile = [
3995
+ # '150', # Group3G/Quam
3996
+ # '151', # T-Mobile
3997
+ # '152', # Vodafone
3998
+ # '155', # E-Plus
3999
+ # '156', # Mobilcom
4000
+ # '157', # E-Plus
4001
+ # '159', # O2
4002
+ # '160', # T-Mobile
4003
+ # '161', # C-Netz
4004
+ # '162', # Vodafone
4005
+ # '163', # E-Plus
4006
+ # '164', # Cityruf
4007
+ # '165', # Quix
4008
+ # '166', # Telmi
4009
+ # '168', # Scall
4010
+ # '169', # Cityruf, Scall, Skyper (e*cityruf, e*message, e*skyper)
4011
+ # '170', # T-Mobile
4012
+ # '171', # T-Mobile
4013
+ # '172', # Vodafone
4014
+ # '173', # Vodafone
4015
+ # '174', # Vodafone
4016
+ # '175', # T-Mobile
4017
+ # '176', # O2 Germany
4018
+ # '177', # E-Plus
4019
+ # '178', # E-Plus
4020
+ # '179', # O2 Germany
4021
+ # ]
4022
+ service = [
4023
4023
  '12', # Innovative Services
4024
4024
  '130',
4025
4025
  '180', #
@@ -4066,4 +4066,7 @@ Phony::Countries::Germany = Phony::Country.configured :local_format => [3, 10],
4066
4066
  '9005',
4067
4067
  '9009',
4068
4068
  ]
4069
- }
4069
+
4070
+ Phony::Countries::Germany = one_of(service) >> split(3,10) |
4071
+ match(/^(1[567]\d)\d*$/) >> split(3,10) | # Mobile
4072
+ one_of(ndcs, :max_length => 5) >> split(3,10)