phony 1.2.11 → 1.3.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 (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,30 +1,26 @@
1
+ include Phony::DSL
2
+
1
3
  # Greece uses a variable-length ndc code, thus we use a separate file to not let all_other.rb explode.
2
4
  #
3
5
  # Note: Greece uses a variable ndc format from length 2 to 4.
4
6
  # To save space, we only use ndcs of length up to 3 (and use the fallback).
5
7
  #
6
- Phony::Countries::Greece = Phony::Country.configured :local_format => [6],
7
- :ndc_fallback_length => 4,
8
- :ndc_mapping => {
9
- :landline => [
10
- '21', # Athens
11
- '231', # Thessaloniki
12
- '241', # Larissa
13
- '251', # Kavala
14
- '261', # Patras
15
- '271', # Tripoli
16
- '281', # Heraklion
17
- ],
18
- :mobile => [
19
- '690',
20
- '693',
21
- '694',
22
- '695',
23
- '697',
24
- '698',
25
- '699'
26
- ],
27
- :service => [ # TODO
28
- '800'
29
- ]
30
- }
8
+ ndcs = [
9
+ '21', # Athens
10
+ '231', # Thessaloniki
11
+ '241', # Larissa
12
+ '251', # Kavala
13
+ '261', # Patras
14
+ '271', # Tripoli
15
+ '281', # Heraklion
16
+ '690', # Mobile
17
+ '693', # Mobile
18
+ '694', # Mobile
19
+ '695', # Mobile
20
+ '697', # Mobile
21
+ '698', # Mobile
22
+ '699', # Mobile
23
+ '800' # Service
24
+ ]
25
+
26
+ Phony::Countries::Greece = one_of(ndcs, :max_length => 4) >> split(6)
@@ -1,23 +1,10 @@
1
+ include Phony::DSL
2
+
1
3
  # Hungarian phone numbers.
2
4
  #
3
5
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Hungary
4
6
  #
5
- Phony::Countries::Hungary = Phony::Country.configured :local_format => [3, 4], # Also captures 3, 3 on a fallback.
6
- :local_special_format => [3, 3],
7
- :ndc_fallback_length => 2,
8
- :ndc_mapping => {
9
- # 1 is Budapest.
10
- # All others are captured using
11
- # the fallback length 2.
12
- #
13
- :landline => [
14
- '1'
15
- ],
16
- # TODO :mobile => [],
17
- :service => [
18
- '104',
19
- '105',
20
- '107',
21
- '112'
22
- ]
23
- }
7
+ Phony::Countries::Hungary = one_of('104', '105', '107', '112') >> split(3,3) |
8
+ # special
9
+ # TODO mobile
10
+ one_of('1', :max_length => 2) >> split(3,4)
@@ -1,156 +1,178 @@
1
+ include Phony::DSL
2
+
1
3
  # Italian phone numbers.
2
4
  #
3
5
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Italy
4
6
  #
5
- Phony::Countries::Italy = Phony::Country.configured :local_format => [3, 4],
6
- :local_special_format => [3, 3],
7
- :normalize => false,
8
- :ndc_fallback_length => 3,
9
- :ndc_mapping => {
10
- :landline => [
11
- '010', # Genoa
12
- '011', # Turin
13
- '0122', # Sestrieres, Bardonecchia and other Susa Valley mountain resorts
14
- '0125', # Ivrea
15
- '0131', # Alessandria
16
- '0141', # Asti
17
- '015', # Biella
18
- '0161', # Vercelli
19
- '0165', # Aosta, Courmayeur
20
- '0166', # Cervinia
21
- '0171', # Cuneo
22
- '0185', # Tigullio
23
- '0187', # La Spezia and Cinque Terre
24
- '019', # Savona
25
- '02', # Milan
26
- '030', # Brescia
27
- '031', # Como
28
- '0321', # Novara
29
- '0331', # Varese
30
- '0341', # Lecco
31
- '0342', # Sondrio
32
- '035', # Bergamo
33
- '0369', # Mediaset Cologno Monzese and Segrate TV studios, geographical rate (used for polls, television programs, etc.)
34
- '0376', # Mantua
35
- '0382', # Pavia
36
- '039', # Monza
37
- '040', # Trieste
38
- '041', # Venice
39
- '0425', # Rovigo
40
- '0432', # Udine
41
- '0444', # Vicenza
42
- '045', # Verona
43
- '0461', # Trento
44
- '0471', # Bolzano
45
- '0481', # Gorizia
46
- '049', # Padua
47
- '050', # Pisa
48
- '051', # Bologna
49
- '0521', # Parma
50
- '0522', # Reggio nell'Emilia
51
- '0523', # Piacenza
52
- '0532', # Ferrara
53
- '0536', # Sassuolo
54
- '0541', # Rimini
55
- '0549', # San Marino (Most Serene Republic of San Marino)
56
- '055', # Florence
57
- '0573', # Pistoia
58
- '0577', # Siena
59
- '0586', # Livorno
60
- '059', # Modena
61
- '06', # Rome (including State of Vatican City) and Aprilia
62
- '070', # Cagliari
63
- '071', # Ancona
64
- '075', # Perugia
65
- '0769', # RAI Saxa Rubra Studios, geographical rate (used for polls, television programs, etc.)
66
- '0771', # Fondi
67
- '0773', # Latina
68
- '0775', # Frosinone
69
- '0789', # Olbia and Costa Smeralda
70
- '079', # Sassari
71
- '080', # Bari
72
- '081', # Naples
73
- '0823', # Caserta
74
- '0824', # Benevento
75
- '0825', # Avellino
76
- '085', # Pescara
77
- '0865', # Isernia
78
- '0871', # Chieti
79
- '0872', # Lanciano
80
- '0873', # Vasto
81
- '0874', # Campobasso
82
- '0875', # Termoli
83
- '0881', # Foggia
84
- '089', # Salerno
85
- '090', # Messina
86
- '091', # Palermo
87
- '092', # Agrigento
88
- '095', # Catania
89
- '0961', # Catanzaro
90
- '0965', # Reggio di Calabria
91
- '0971', # Potenza
92
- '099', # Taranto
93
- ],
94
- :mobile => [
95
- '310',
96
- '31100',
97
- '31101',
98
- '31102',
99
- '31103',
100
- '31104',
101
- '31105',
102
- '313',
103
- '319',
104
- ('3200'..'3209').to_a,
105
- '322',
106
- ('3230'..'3239').to_a,
107
- ('3270'..'3279').to_a,
108
- ('3280'..'3289').to_a,
109
- ('3290'..'3299').to_a,
110
- ('3300'..'3309').to_a,
111
- '331',
112
- ('3330'..'3339').to_a,
113
- ('3340'..'3349').to_a,
114
- ('3350'..'3359').to_a,
115
- ('3360'..'3369').to_a,
116
- ('3370'..'3379').to_a,
117
- ('3380'..'3389').to_a,
118
- ('3390'..'3399').to_a,
119
- ('3400'..'3409').to_a,
120
- '341',
121
- ('3430'..'3439').to_a,
122
- '345',
123
- ('3460'..'3469').to_a,
124
- ('3470'..'3479').to_a,
125
- ('3480'..'3489').to_a,
126
- ('3490'..'3499').to_a,
127
- '350',
128
- ('3600'..'3609').to_a,
129
- '361',
130
- '362',
131
- ('3630'..'3639').to_a,
132
- ('3660'..'3669').to_a,
133
- ('3680'..'3689').to_a,
134
- '370',
135
- '373',
136
- '377',
137
- ('3800'..'3809').to_a,
138
- ('3880'..'3889').to_a,
139
- ('3890'..'3899').to_a,
140
- ('3900'..'3909').to_a,
141
- ('3910'..'3919').to_a,
142
- ('3920'..'3929').to_a,
143
- ('3930'..'3939').to_a,
144
- '397'
145
- ].flatten,
146
- :service => [ # Not exhaustive.
147
- '112',
148
- '113',
149
- '115',
150
- '117',
151
- '118',
152
- '1515',
153
- '1518',
154
- '1530'
155
- ]
156
- }
7
+ ndcs = [
8
+ '010', # Genoa
9
+ '011', # Turin
10
+ '0122', # Sestrieres, Bardonecchia and other Susa Valley mountain resorts
11
+ '0125', # Ivrea
12
+ '0131', # Alessandria
13
+ '0141', # Asti
14
+ '015', # Biella
15
+ '0161', # Vercelli
16
+ '0165', # Aosta, Courmayeur
17
+ '0166', # Cervinia
18
+ '0171', # Cuneo
19
+ '0185', # Tigullio
20
+ '0187', # La Spezia and Cinque Terre
21
+ '019', # Savona
22
+ '02', # Milan
23
+ '030', # Brescia
24
+ '031', # Como
25
+ '0321', # Novara
26
+ '0331', # Varese
27
+ '0341', # Lecco
28
+ '0342', # Sondrio
29
+ '035', # Bergamo
30
+ '0369', # Mediaset Cologno Monzese and Segrate TV studios, geographical rate (used for polls, television programs, etc.)
31
+ '0376', # Mantua
32
+ '0382', # Pavia
33
+ '039', # Monza
34
+ '040', # Trieste
35
+ '041', # Venice
36
+ '0425', # Rovigo
37
+ '0432', # Udine
38
+ '0444', # Vicenza
39
+ '045', # Verona
40
+ '0461', # Trento
41
+ '0471', # Bolzano
42
+ '0481', # Gorizia
43
+ '049', # Padua
44
+ '050', # Pisa
45
+ '051', # Bologna
46
+ '0521', # Parma
47
+ '0522', # Reggio nell'Emilia
48
+ '0523', # Piacenza
49
+ '0532', # Ferrara
50
+ '0536', # Sassuolo
51
+ '0541', # Rimini
52
+ '0549', # San Marino (Most Serene Republic of San Marino)
53
+ '055', # Florence
54
+ '0573', # Pistoia
55
+ '0577', # Siena
56
+ '0586', # Livorno
57
+ '059', # Modena
58
+ '06', # Rome (including State of Vatican City) and Aprilia
59
+ '070', # Cagliari
60
+ '071', # Ancona
61
+ '075', # Perugia
62
+ '0769', # RAI Saxa Rubra Studios, geographical rate (used for polls, television programs, etc.)
63
+ '0771', # Fondi
64
+ '0773', # Latina
65
+ '0775', # Frosinone
66
+ '0789', # Olbia and Costa Smeralda
67
+ '079', # Sassari
68
+ '080', # Bari
69
+ '081', # Naples
70
+ '0823', # Caserta
71
+ '0824', # Benevento
72
+ '0825', # Avellino
73
+ '085', # Pescara
74
+ '0865', # Isernia
75
+ '0871', # Chieti
76
+ '0872', # Lanciano
77
+ '0873', # Vasto
78
+ '0874', # Campobasso
79
+ '0875', # Termoli
80
+ '0881', # Foggia
81
+ '089', # Salerno
82
+ '090', # Messina
83
+ '091', # Palermo
84
+ '092', # Agrigento
85
+ '095', # Catania
86
+ '0961', # Catanzaro
87
+ '0965', # Reggio di Calabria
88
+ '0971', # Potenza
89
+ '099', # Taranto
90
+ ]
91
+
92
+ mobile = [
93
+ '310',
94
+ '31100',
95
+ '31101',
96
+ '31102',
97
+ '31103',
98
+ '31104',
99
+ '31105',
100
+ '313',
101
+ '319',
102
+ ('3200'..'3209').to_a,
103
+ '322',
104
+ ('3230'..'3239').to_a,
105
+ ('3270'..'3279').to_a,
106
+ ('3280'..'3289').to_a,
107
+ ('3290'..'3299').to_a,
108
+ ('3300'..'3309').to_a,
109
+ '331',
110
+ ('3330'..'3339').to_a,
111
+ ('3340'..'3349').to_a,
112
+ ('3350'..'3359').to_a,
113
+ ('3360'..'3369').to_a,
114
+ ('3370'..'3379').to_a,
115
+ ('3380'..'3389').to_a,
116
+ ('3390'..'3399').to_a,
117
+ ('3400'..'3409').to_a,
118
+ '341',
119
+ ('3430'..'3439').to_a,
120
+ '345',
121
+ ('3460'..'3469').to_a,
122
+ ('3470'..'3479').to_a,
123
+ ('3480'..'3489').to_a,
124
+ ('3490'..'3499').to_a,
125
+ '350',
126
+ ('3600'..'3609').to_a,
127
+ '361',
128
+ '362',
129
+ ('3630'..'3639').to_a,
130
+ ('3660'..'3669').to_a,
131
+ ('3680'..'3689').to_a,
132
+ '370',
133
+ '373',
134
+ '377',
135
+ ('3800'..'3809').to_a,
136
+ ('3880'..'3889').to_a,
137
+ ('3890'..'3899').to_a,
138
+ ('3900'..'3909').to_a,
139
+ ('3910'..'3919').to_a,
140
+ ('3920'..'3929').to_a,
141
+ ('3930'..'3939').to_a,
142
+ '397'
143
+ ].flatten
144
+
145
+ service = [ # Not exhaustive.
146
+ '112',
147
+ '113',
148
+ '115',
149
+ '117',
150
+ '118',
151
+ '1515',
152
+ '1518',
153
+ '1530'
154
+ ]
155
+
156
+ # TODO Normalize!
157
+ #
158
+ # Phony::Countries::Italy = one_of(*service) >> split(3,3) |
159
+ # one_of(*mobile) >> split(3,4) |
160
+ # one_of(*ndcs, :max_length => 3) >> split(3,4)
161
+
162
+ handlers = []
163
+ handlers << Phony::NationalCode.new(
164
+ Phony::NationalSplitters::Variable.new(nil, service),
165
+ Phony::LocalSplitters::Fixed.instance_for([4, 4]),
166
+ false
167
+ )
168
+ handlers << Phony::NationalCode.new(
169
+ Phony::NationalSplitters::Variable.new(nil, mobile),
170
+ Phony::LocalSplitters::Fixed.instance_for([3, 4]),
171
+ false
172
+ )
173
+ handlers << Phony::NationalCode.new(
174
+ Phony::NationalSplitters::Variable.new(3, ndcs),
175
+ Phony::LocalSplitters::Fixed.instance_for([3, 4]),
176
+ false
177
+ )
178
+ Phony::Countries::Italy = Phony::Country.new *handlers
@@ -1,21 +1,21 @@
1
+ include Phony::DSL
2
+
1
3
  # Malaysian phone numbers.
2
4
  #
3
5
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Malaysia
4
6
  #
5
- Phony::Countries::Malaysia = Phony::Country.configured :local_format => [8],
6
- :ndc_fallback_length => 2,
7
- :ndc_mapping => {
8
- :landline => [
9
- '2', # Singapore
10
- '3', # Selangor & Federal Territories of Kuala Lumpur & Putrajaya & also Genting Highlands, Pahang
11
- '4', # Kedah, Penang & Perlis
12
- '5', # Perak & Cameron Highlands (Pahang)
13
- '6', # Melaka, Negeri Sembilan & Muar (Johor)
14
- '7', # Johor (except Muar)
15
- '9', # Kelantan, Pahang (except Cameron Highlands & Genting Highlands) & Terengganu
16
- ],
17
- :mobile => %w{ 10 11 12 13 14 153 154 156 158 16 17 18 19 },
18
- # TODO 4+ digits service numbers
19
- #
20
- :service => %w{ 100 101 102 103 104 108 112 991 994 995 999 }
21
- }
7
+ ndcs = [
8
+ '2', # Singapore
9
+ '3', # Selangor & Federal Territories of Kuala Lumpur & Putrajaya & also Genting Highlands, Pahang
10
+ '4', # Kedah, Penang & Perlis
11
+ '5', # Perak & Cameron Highlands (Pahang)
12
+ '6', # Melaka, Negeri Sembilan & Muar (Johor)
13
+ '7', # Johor (except Muar)
14
+ '9', # Kelantan, Pahang (except Cameron Highlands & Genting Highlands) & Terengganu
15
+ ]
16
+ mobile = %w{ 10 11 12 13 14 153 154 156 158 16 17 18 19 }
17
+ service = %w{ 100 101 102 103 104 108 112 991 994 995 999 }
18
+
19
+ Phony::Countries::Malaysia = one_of(service) >> split(3,3) |
20
+ one_of(mobile) >> split(8) |
21
+ one_of(ndcs, :max_length => 2) >> split(8)