phony 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +14 -2
- data/lib/phony.rb +58 -463
- data/lib/phony/countries/all_other.rb +417 -0
- data/lib/phony/countries/austria.rb +69 -0
- data/lib/phony/countries/egypt.rb +40 -0
- data/lib/phony/countries/germany.rb +156 -0
- data/lib/phony/countries/greece.rb +30 -0
- data/lib/phony/countries/hungary.rb +23 -0
- data/lib/phony/countries/italy.rb +105 -0
- data/lib/phony/country.rb +102 -0
- data/lib/phony/country_codes.rb +102 -0
- data/lib/phony/local_splitter.rb +46 -0
- data/lib/phony/national_code.rb +27 -0
- data/lib/phony/national_splitters/fixed.rb +36 -0
- data/lib/phony/national_splitters/variable.rb +64 -0
- data/lib/phony/vanity.rb +35 -0
- data/spec/lib/phony/countries/austria_spec.rb +24 -0
- data/spec/lib/phony/countries/egypt_spec.rb +18 -0
- data/spec/lib/phony/countries/germany_spec.rb +24 -0
- data/spec/lib/phony/countries/greece_spec.rb +18 -0
- data/spec/lib/phony/countries/hungary_spec.rb +18 -0
- data/spec/lib/phony/countries/switzerland_spec.rb +18 -0
- data/spec/lib/phony/country_codes_spec.rb +110 -0
- data/spec/lib/phony/country_spec.rb +91 -0
- data/spec/lib/phony/local_splitter_spec.rb +48 -0
- data/spec/lib/phony/national_code_spec.rb +36 -0
- data/spec/lib/phony/national_splitters/fixed_spec.rb +43 -0
- data/spec/lib/phony/national_splitters/variable_spec.rb +35 -0
- data/spec/lib/phony/vanity_spec.rb +34 -0
- data/spec/lib/phony_spec.rb +117 -238
- metadata +45 -21
- data/lib/ndc/austria.rb +0 -69
- data/lib/ndc/fixed_size.rb +0 -113
- data/lib/ndc/germany.rb +0 -157
- data/lib/ndc/prefix.rb +0 -67
- data/lib/ndc/splitter.rb +0 -81
- data/spec/lib/ndc/austria_spec.rb +0 -40
- data/spec/lib/ndc/fixed_size_spec.rb +0 -65
- data/spec/lib/ndc/germany_spec.rb +0 -40
- data/spec/lib/ndc/prefix_spec.rb +0 -25
- data/spec/lib/ndc/splitter_spec.rb +0 -59
@@ -0,0 +1,40 @@
|
|
1
|
+
# Egyptian phone numbers.
|
2
|
+
#
|
3
|
+
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Egypt
|
4
|
+
#
|
5
|
+
Phony::Countries::Egypt = Phony::Country.configured :local_format => [8],
|
6
|
+
:local_special_format => [7],
|
7
|
+
:ndc_fallback_length => 2,
|
8
|
+
:ndc_mapping => {
|
9
|
+
:landline => [
|
10
|
+
'2', # Cairo/Giza
|
11
|
+
'3', # Alexandria
|
12
|
+
'13', # Banha
|
13
|
+
'15', # 10th of Ramadan
|
14
|
+
'45', # Damanhur
|
15
|
+
'46', # Marsa Matruh
|
16
|
+
'47', # Kafer El Sheik
|
17
|
+
'48', # Monufia
|
18
|
+
'50', # Mansoura
|
19
|
+
'55', # Zazazig
|
20
|
+
'56', # Spare
|
21
|
+
'57', # Damiette
|
22
|
+
'62', # Suez
|
23
|
+
'64', # Ismailia
|
24
|
+
'65', # Red Sea
|
25
|
+
'66', # Port Said
|
26
|
+
'68', # El Arish
|
27
|
+
'69', # El-Tor
|
28
|
+
'82', # Beni Suef
|
29
|
+
'84', # Fayoum
|
30
|
+
'86', # Minia
|
31
|
+
'88', # Assiout
|
32
|
+
'92', # Wadi El Gehid
|
33
|
+
'93', # Sohag
|
34
|
+
'95', # Luxor
|
35
|
+
'96', # Qunea
|
36
|
+
'97', # Aswan
|
37
|
+
],
|
38
|
+
:mobile => %w{10 11 12 14 16 17 18 19},
|
39
|
+
:service => %w{800} # Not exhaustive.
|
40
|
+
}
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# Germany uses a variable-length ndc code, thus we use a separate file to not let all_other.rb explode.
|
2
|
+
#
|
3
|
+
# Note: Germany uses a variable ndc format from length 2 to 5.
|
4
|
+
# To save space, we only use ndcs up to length 4.
|
5
|
+
#
|
6
|
+
Phony::Countries::Germany = Phony::Country.configured :local_format => [3, 10],
|
7
|
+
:local_special_format => [3, 10],
|
8
|
+
:ndc_fallback_length => 4,
|
9
|
+
:ndc_mapping => {
|
10
|
+
:landline => ['10', # Call-By-Call
|
11
|
+
'11', # formerly Value Added Services
|
12
|
+
'12', # Innovative Services
|
13
|
+
'13', # Voting and Lottery Numbers
|
14
|
+
'30', # Berlin
|
15
|
+
'32', # Non Geographical Numbers
|
16
|
+
'40', # Hamburg
|
17
|
+
'69', # Frankfurt am Main
|
18
|
+
'89', # München
|
19
|
+
'201', # Essen
|
20
|
+
'202', # Wuppertal
|
21
|
+
'203', # Duisburg
|
22
|
+
'208', # Mühlheim an der Ruhr
|
23
|
+
'209', # Gelsenkirchen
|
24
|
+
'211', # Düsseldorf
|
25
|
+
'212', # Solingen
|
26
|
+
'214', # Leverkusen
|
27
|
+
'221', # Köln
|
28
|
+
'228', # Bonn
|
29
|
+
'231', # Dortmund
|
30
|
+
'234', # Bochum
|
31
|
+
'241', # Aachen
|
32
|
+
'251', # Münster
|
33
|
+
'261', # Koblenz
|
34
|
+
'271', # Siegen
|
35
|
+
'281', # Wesel
|
36
|
+
'291', # Meschede
|
37
|
+
'310', # Test Number Long Distance
|
38
|
+
'311', # Test Number Local
|
39
|
+
'335', # Frankfurt (Oder)
|
40
|
+
'340', # Dessau
|
41
|
+
'341', # Leipzig
|
42
|
+
'345', # Halle (Saale)
|
43
|
+
'351', # Dresden
|
44
|
+
'355', # Cottbus
|
45
|
+
'361', # Erfurt
|
46
|
+
'365', # Gera
|
47
|
+
'371', # Chemnitz
|
48
|
+
'375', # Zwickau
|
49
|
+
'381', # Rostock
|
50
|
+
'385', # Schwerin
|
51
|
+
'391', # Magdeburg
|
52
|
+
'395', # Neubrandenburg
|
53
|
+
'421', # Bremen
|
54
|
+
'431', # Kiel
|
55
|
+
'441', # Oldenburg
|
56
|
+
'461', # Flensburg
|
57
|
+
'471', # Bremerhaven
|
58
|
+
'481', # Heide
|
59
|
+
'491', # Leer
|
60
|
+
'511', # Hannover
|
61
|
+
'521', # Bielefeld
|
62
|
+
'531', # Braunschweig
|
63
|
+
'541', # Osnabrück
|
64
|
+
'551', # Göttingen
|
65
|
+
'561', # Kassel
|
66
|
+
'571', # Minden
|
67
|
+
'581', # Uelzen
|
68
|
+
'591', # Lingen (Ems)
|
69
|
+
'611', # Wiesbaden
|
70
|
+
'621', # Mannheim / Ludwigshafen
|
71
|
+
'631', # Kaiserslautern
|
72
|
+
'641', # Gießen
|
73
|
+
'651', # Trier
|
74
|
+
'661', # Fulda
|
75
|
+
'671', # Bad Kreuznach
|
76
|
+
'681', # Saarbrücken
|
77
|
+
'700', # Personal Numbers
|
78
|
+
'701', # Personal Numbers, reserved
|
79
|
+
'711', # Stuttgart
|
80
|
+
'721', # Karlsruhe
|
81
|
+
'731', # Ulm
|
82
|
+
'741', # Rottweil
|
83
|
+
'751', # Ravensburg
|
84
|
+
'761', # Freiburg im Breisgau
|
85
|
+
'771', # Donaueschingen
|
86
|
+
'781', # Offenburg
|
87
|
+
'791', # Schwäbisch Hall
|
88
|
+
'800', # Toll-Free Numbers
|
89
|
+
'801', # Toll-Free Numbers, reserved
|
90
|
+
'811', # Hallbergmoos
|
91
|
+
'821', # Augsburg
|
92
|
+
'831', # Kempten
|
93
|
+
'841', # Ingolstadt
|
94
|
+
'851', # Passau
|
95
|
+
'861', # Traunstein
|
96
|
+
'871', # Landshut
|
97
|
+
'881', # Weilheim in Oberbayern
|
98
|
+
'900', # Premium Rate Numbers
|
99
|
+
'901', # Premium Rate Numbers, reserved
|
100
|
+
'902', # Replacement for 0137/0138
|
101
|
+
'906', # Donauwörth
|
102
|
+
'911', # Nürnberg
|
103
|
+
'921', # Bayreuth
|
104
|
+
'931', # Würzburg
|
105
|
+
'941', # Regensburg
|
106
|
+
'951', # Bamberg
|
107
|
+
'961', # Weiden
|
108
|
+
'971', # Bad Kissingen
|
109
|
+
'981', # Ansbach
|
110
|
+
'991', # Deggendorf
|
111
|
+
],
|
112
|
+
:mobile => [
|
113
|
+
'150', # Group3G/Quam
|
114
|
+
'151', # T-Mobile
|
115
|
+
'152', # Vodafone
|
116
|
+
'155', # E-Plus
|
117
|
+
'156', # Mobilcom
|
118
|
+
'157', # E-Plus
|
119
|
+
'159', # O2
|
120
|
+
'160', # T-Mobile
|
121
|
+
'161', # C-Netz
|
122
|
+
'162', # Vodafone
|
123
|
+
'163', # E-Plus
|
124
|
+
'164', # Cityruf
|
125
|
+
'165', # Quix
|
126
|
+
'166', # Telmi
|
127
|
+
'168', # Scall
|
128
|
+
'169', # Cityruf, Scall, Skyper (e*cityruf, e*message, e*skyper)
|
129
|
+
'170', # T-Mobile
|
130
|
+
'171', # T-Mobile
|
131
|
+
'172', # Vodafone
|
132
|
+
'173', # Vodafone
|
133
|
+
'174', # Vodafone
|
134
|
+
'175', # T-Mobile
|
135
|
+
'176', # O2 Germany
|
136
|
+
'177', # E-Plus
|
137
|
+
'178', # E-Plus
|
138
|
+
'179', # O2 Germany
|
139
|
+
],
|
140
|
+
:service => [
|
141
|
+
'181', # IVPNs
|
142
|
+
'182', # Closed User Group
|
143
|
+
'183', # Closed User Group
|
144
|
+
'184', # Closed User Group
|
145
|
+
'185', # Closed User Group
|
146
|
+
'186', # Closed User Group
|
147
|
+
'187', # Closed User Group
|
148
|
+
'189', # Closed User Group
|
149
|
+
'190', # former Premium Rate Services
|
150
|
+
'191', # Online Services
|
151
|
+
'192', # Online Services
|
152
|
+
'193', # Online Services
|
153
|
+
'194', # Online Services
|
154
|
+
'199', # Network-Internal Traffic Control
|
155
|
+
]
|
156
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Greece uses a variable-length ndc code, thus we use a separate file to not let all_other.rb explode.
|
2
|
+
#
|
3
|
+
# Note: Greece uses a variable ndc format from length 2 to 4.
|
4
|
+
# To save space, we only use ndcs of length up to 3 (and use the fallback).
|
5
|
+
#
|
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
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Hungarian phone numbers.
|
2
|
+
#
|
3
|
+
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Hungary
|
4
|
+
#
|
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
|
+
:mobile => [], # TODO
|
17
|
+
:service => [
|
18
|
+
'104',
|
19
|
+
'105',
|
20
|
+
'107',
|
21
|
+
'112'
|
22
|
+
]
|
23
|
+
}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# Italian phone numbers.
|
2
|
+
#
|
3
|
+
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Italy
|
4
|
+
#
|
5
|
+
Phony::Countries::Italy = Phony::Country.configured :local_format => [3, 4],
|
6
|
+
:local_special_format => [3, 3],
|
7
|
+
:ndc_fallback_length => 3,
|
8
|
+
:ndc_mapping => {
|
9
|
+
:landline => [
|
10
|
+
'10', # Genoa
|
11
|
+
'11', # Turin
|
12
|
+
'122', # Sestrieres, Bardonecchia and other Susa Valley mountain resorts
|
13
|
+
'125', # Ivrea
|
14
|
+
'131', # Alessandria
|
15
|
+
'141', # Asti
|
16
|
+
'15', # Biella
|
17
|
+
'161', # Vercelli
|
18
|
+
'165', # Aosta, Courmayeur
|
19
|
+
'166', # Cervinia
|
20
|
+
'171', # Cuneo
|
21
|
+
'185', # Tigullio
|
22
|
+
'187', # La Spezia and Cinque Terre
|
23
|
+
'19', # Savona
|
24
|
+
'2', # Milan
|
25
|
+
'30', # Brescia
|
26
|
+
'31', # Como
|
27
|
+
'321', # Novara
|
28
|
+
'331', # Varese
|
29
|
+
'341', # Lecco
|
30
|
+
'342', # Sondrio
|
31
|
+
'35', # Bergamo
|
32
|
+
'369', # Mediaset Cologno Monzese and Segrate TV studios, geographical rate (used for polls, television programs, etc.)
|
33
|
+
'376', # Mantua
|
34
|
+
'382', # Pavia
|
35
|
+
'39', # Monza
|
36
|
+
'40', # Trieste
|
37
|
+
'41', # Venice
|
38
|
+
'425', # Rovigo
|
39
|
+
'432', # Udine
|
40
|
+
'444', # Vicenza
|
41
|
+
'45', # Verona
|
42
|
+
'461', # Trento
|
43
|
+
'471', # Bolzano
|
44
|
+
'481', # Gorizia
|
45
|
+
'49', # Padua
|
46
|
+
'50', # Pisa
|
47
|
+
'51', # Bologna
|
48
|
+
'521', # Parma
|
49
|
+
'522', # Reggio nell'Emilia
|
50
|
+
'523', # Piacenza
|
51
|
+
'532', # Ferrara
|
52
|
+
'536', # Sassuolo
|
53
|
+
'541', # Rimini
|
54
|
+
'549', # San Marino (Most Serene Republic of San Marino)
|
55
|
+
'55', # Florence
|
56
|
+
'573', # Pistoia
|
57
|
+
'577', # Siena
|
58
|
+
'586', # Livorno
|
59
|
+
'59', # Modena
|
60
|
+
'6', # Rome (including State of Vatican City) and Aprilia
|
61
|
+
'70', # Cagliari
|
62
|
+
'71', # Ancona
|
63
|
+
'75', # Perugia
|
64
|
+
'769', # RAI Saxa Rubra Studios, geographical rate (used for polls, television programs, etc.)
|
65
|
+
'771', # Fondi
|
66
|
+
'773', # Latina
|
67
|
+
'775', # Frosinone
|
68
|
+
'789', # Olbia and Costa Smeralda
|
69
|
+
'79', # Sassari
|
70
|
+
'80', # Bari
|
71
|
+
'81', # Naples
|
72
|
+
'823', # Caserta
|
73
|
+
'824', # Benevento
|
74
|
+
'825', # Avellino
|
75
|
+
'85', # Pescara
|
76
|
+
'865', # Isernia
|
77
|
+
'871', # Chieti
|
78
|
+
'872', # Lanciano
|
79
|
+
'873', # Vasto
|
80
|
+
'874', # Campobasso
|
81
|
+
'875', # Termoli
|
82
|
+
'881', # Foggia
|
83
|
+
'89', # Salerno
|
84
|
+
'90', # Messina
|
85
|
+
'91', # Palermo
|
86
|
+
'92', # Agrigento
|
87
|
+
'95', # Catania
|
88
|
+
'961', # Catanzaro
|
89
|
+
'965', # Reggio di Calabria
|
90
|
+
'971', # Potenza
|
91
|
+
'99', # Taranto
|
92
|
+
],
|
93
|
+
:mobile => [], # TODO
|
94
|
+
:service => [ # Not exhaustive.
|
95
|
+
'112',
|
96
|
+
'113',
|
97
|
+
'115',
|
98
|
+
'117',
|
99
|
+
'118',
|
100
|
+
'878',
|
101
|
+
'1515',
|
102
|
+
'1518',
|
103
|
+
'1530'
|
104
|
+
]
|
105
|
+
}
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Phony
|
2
|
+
|
3
|
+
#
|
4
|
+
#
|
5
|
+
class Country
|
6
|
+
|
7
|
+
def initialize national_code, special_code = nil
|
8
|
+
@national_code = national_code
|
9
|
+
@special_code = special_code
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
#
|
14
|
+
def split national_number
|
15
|
+
ndc, *rest = @special_code.split national_number if @special_code
|
16
|
+
ndc, *rest = @national_code.split national_number unless rest && !rest.empty?
|
17
|
+
[ndc, *rest]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Is this national number a vanity number?
|
21
|
+
#
|
22
|
+
def vanity? national_number
|
23
|
+
Vanity.vanity? national_number
|
24
|
+
end
|
25
|
+
#
|
26
|
+
#
|
27
|
+
def vanity_to_number vanity_number
|
28
|
+
ndc, *rest = split vanity_number
|
29
|
+
"#{ndc}#{Vanity.replace(rest.join)}"
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
# Get a configured country instance.
|
34
|
+
#
|
35
|
+
# Define your countries like this:
|
36
|
+
# Phony::Countries::Austria = Phony::Country.configured <options>
|
37
|
+
#
|
38
|
+
# Example:
|
39
|
+
# Phony::Country.configured :local_format => [3, 2, 2],
|
40
|
+
# :service_local_format => [3, 3],
|
41
|
+
# :ndc_fallback_length => 4,
|
42
|
+
# :ndc_mapping => {
|
43
|
+
# :normal => ['44'],
|
44
|
+
# :service => ['800'],
|
45
|
+
# :mobile => ['76']
|
46
|
+
# }
|
47
|
+
#
|
48
|
+
# Service numbers can have a special formatting.
|
49
|
+
# Cellphones usually use the same as the landline.
|
50
|
+
# If that is not the case, I will expand the framework.
|
51
|
+
#
|
52
|
+
def self.configured options = {}
|
53
|
+
ndc_fallback_length = options[:ndc_fallback_length]
|
54
|
+
ndc_mapping = options[:ndc_mapping] || raise("No ndc_mapping given!")
|
55
|
+
|
56
|
+
national_splitter = Phony::NationalSplitters::Variable.new ndc_fallback_length, ndc_mapping
|
57
|
+
local_splitter = Phony::LocalSplitter.instance_for options[:local_format] || [3, 2, 2]
|
58
|
+
national_code = Phony::NationalCode.new national_splitter, local_splitter
|
59
|
+
|
60
|
+
if ndc_mapping[:service]
|
61
|
+
service_national_splitter = Phony::NationalSplitters::Variable.new nil, :service => ndc_mapping[:service]
|
62
|
+
service_local_splitter = Phony::LocalSplitter.instance_for options[:service_local_format] || [3, 3]
|
63
|
+
service_code = Phony::NationalCode.new service_national_splitter, service_local_splitter
|
64
|
+
end
|
65
|
+
|
66
|
+
new national_code, service_code
|
67
|
+
end
|
68
|
+
|
69
|
+
# Gets a configured country instance with fixed length ndc code.
|
70
|
+
#
|
71
|
+
# Define your countries like this:
|
72
|
+
# Phony::Countries::Switzerland = Phony::Country.fixed <options>
|
73
|
+
#
|
74
|
+
# Example:
|
75
|
+
# Phony::Country.fixed :ndc_length => 4,
|
76
|
+
# :local_format => [3, 2, 2],
|
77
|
+
# :service_local_format => [3, 3],
|
78
|
+
# :service_ndcs => ['800']
|
79
|
+
#
|
80
|
+
def self.fixed options = {}
|
81
|
+
ndc_length = options[:ndc_length]
|
82
|
+
service_ndcs = options[:service_ndcs]
|
83
|
+
local_format = options[:local_format]
|
84
|
+
|
85
|
+
national_splitter = Phony::NationalSplitters::Fixed.new ndc_length
|
86
|
+
local_splitter = Phony::LocalSplitter.instance_for local_format || [3, 2, 2]
|
87
|
+
national_code = Phony::NationalCode.new national_splitter, local_splitter
|
88
|
+
|
89
|
+
service_code = nil
|
90
|
+
if service_ndcs
|
91
|
+
service_local_format = options[:service_local_format] || local_format
|
92
|
+
service_national_splitter = Phony::NationalSplitters::Variable.new nil, :service => service_ndcs
|
93
|
+
service_local_splitter = Phony::LocalSplitter.instance_for service_local_format || [3, 3]
|
94
|
+
service_code = Phony::NationalCode.new service_national_splitter, service_local_splitter
|
95
|
+
end
|
96
|
+
|
97
|
+
new national_code, service_code
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|