phony 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/phony.rb +0 -5
- data/lib/phony/countries.rb +172 -53
- data/lib/phony/countries/malaysia.rb +4 -3
- data/lib/phony/country_codes.rb +35 -24
- data/spec/lib/phony/countries_spec.rb +8 -4
- data/spec/lib/phony/country_codes_spec.rb +40 -0
- metadata +2 -7
- data/lib/phony/countries/belgium.rb +0 -33
- data/lib/phony/countries/chile.rb +0 -14
- data/lib/phony/countries/greece.rb +0 -26
- data/lib/phony/countries/hungary.rb +0 -10
- data/lib/phony/countries/romania.rb +0 -32
data/lib/phony.rb
CHANGED
@@ -18,16 +18,11 @@ require File.expand_path '../phony/dsl', __FILE__
|
|
18
18
|
# The ones that need more space to define.
|
19
19
|
#
|
20
20
|
require File.expand_path '../phony/countries/austria', __FILE__
|
21
|
-
require File.expand_path '../phony/countries/belgium', __FILE__
|
22
|
-
require File.expand_path '../phony/countries/chile', __FILE__
|
23
21
|
require File.expand_path '../phony/countries/china', __FILE__
|
24
22
|
require File.expand_path '../phony/countries/germany', __FILE__
|
25
|
-
require File.expand_path '../phony/countries/greece', __FILE__
|
26
|
-
require File.expand_path '../phony/countries/hungary', __FILE__
|
27
23
|
require File.expand_path '../phony/countries/italy', __FILE__
|
28
24
|
require File.expand_path '../phony/countries/malaysia', __FILE__
|
29
25
|
require File.expand_path '../phony/countries/netherlands', __FILE__
|
30
|
-
require File.expand_path '../phony/countries/romania', __FILE__
|
31
26
|
require File.expand_path '../phony/countries/south_korea', __FILE__
|
32
27
|
require File.expand_path '../phony/countries/sweden', __FILE__
|
33
28
|
require File.expand_path '../phony/countries/united_kingdom', __FILE__
|
data/lib/phony/countries.rb
CHANGED
@@ -20,79 +20,180 @@
|
|
20
20
|
# Note: The ones that are commented are defined in their special files.
|
21
21
|
#
|
22
22
|
Phony.define do
|
23
|
+
|
24
|
+
# Reserved.
|
25
|
+
#
|
23
26
|
country '0', fixed(1) >> split(10) # Reserved.
|
24
|
-
country '1', fixed(3) >> split(3,4) # USA, Canada, etc.
|
25
|
-
country '7', fixed(3) >> split(3,2,2) # Kazakhstan (Republic of) & Russian Federation
|
26
27
|
|
28
|
+
# USA, Canada, etc.
|
29
|
+
#
|
30
|
+
country '1', fixed(3) >> split(3,4)
|
31
|
+
|
32
|
+
# Kazakhstan (Republic of) & Russian Federation.
|
33
|
+
#
|
34
|
+
country '7', fixed(3) >> split(3,2,2)
|
35
|
+
|
36
|
+
# Egypt.
|
37
|
+
#
|
27
38
|
country '20', one_of('800') >> split(7) | # Egypt
|
28
39
|
one_of('2', '3') >> split(8) | # Cairo/Giza, Alexandria
|
29
40
|
fixed(2) >> split(8)
|
30
41
|
# :mobile? => /^10|11|12|14|16|17|18|19*$/, :service? => /^800.*$/
|
31
|
-
country '27', fixed(2) >> split(3,4) # South Africa
|
32
42
|
|
33
|
-
#
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
#
|
39
|
-
|
43
|
+
# South Africa.
|
44
|
+
#
|
45
|
+
country '27', fixed(2) >> split(3,4)
|
46
|
+
|
47
|
+
# Greece.
|
48
|
+
#
|
49
|
+
country '30', match(/^(2[3-8]?1|69[0345789]|800)\d+$/) >> split(6) | # Geo/Mobile
|
50
|
+
fixed(4) >> split(6) # 3-digit NDCs
|
51
|
+
|
52
|
+
# country '31' # Netherlands, see special file.
|
53
|
+
|
54
|
+
# Belgium.
|
55
|
+
#
|
56
|
+
country '32', match(/^(70|800|90\d)\d+$/) >> split(3,3) | # Service
|
57
|
+
match(/^(4[789]\d)\d{6}$/) >> split(6) | # Mobile
|
58
|
+
one_of('2','3','4','9') >> split(3,5) | # Short NDCs
|
59
|
+
fixed(2) >> split(3,5) # 2-digit NDCs
|
60
|
+
|
61
|
+
# France.
|
62
|
+
#
|
63
|
+
country '33', fixed(1) >> split(2,2,2,2) # :service? => /^8.*$/, :mobile? => /^[67].*$/
|
64
|
+
|
65
|
+
# Spain.
|
66
|
+
#
|
67
|
+
country '34', fixed(2) >> split(3,4)
|
68
|
+
|
69
|
+
# Hungary.
|
70
|
+
#
|
71
|
+
# TODO Mobile.
|
72
|
+
#
|
73
|
+
country '36', one_of('104','105','107','112') >> split(3,3) | # Service
|
74
|
+
one_of('1') >> split(3,4) | # Budapest
|
75
|
+
fixed(2) >> split(3,4) # 2-digit NDCs
|
76
|
+
|
77
|
+
# country '39' # Italy, see special file.
|
40
78
|
|
41
|
-
#
|
79
|
+
# Romania.
|
80
|
+
#
|
81
|
+
country '40', match(/^(112|800|90[036])\d+$/) >> split(3,3) | # Service
|
82
|
+
match(/^(7[1-8])\d+$/) >> split(3,4) | # Mobile
|
83
|
+
one_of('21', '31') >> split(3,4) | # Bucureşti
|
84
|
+
fixed(3) >> split(3,4) # 3-digit NDCs
|
85
|
+
|
86
|
+
# Switzerland.
|
87
|
+
#
|
42
88
|
# :service => %w{800 840 842 844 848}, :mobile => %w{74 76 77 78 79}
|
43
89
|
swiss_service_regex = /^(800|840|842|844|848)\d+$/
|
44
|
-
country '41', match(swiss_service_regex) >> split(3,3) |
|
90
|
+
country '41', match(swiss_service_regex) >> split(3,3) |
|
45
91
|
fixed(2) >> split(3,2,2)
|
46
|
-
|
47
|
-
|
48
|
-
country '
|
49
|
-
# country '
|
50
|
-
|
51
|
-
|
92
|
+
|
93
|
+
|
94
|
+
# country '43' # Austria, see special file.
|
95
|
+
# country '44' # UnitedKingdom, see special file.
|
96
|
+
|
97
|
+
# Denmark.
|
98
|
+
#
|
99
|
+
country '45', none >> split(2,2,2,2)
|
100
|
+
|
101
|
+
# country '46' # Sweden, see special file.
|
102
|
+
|
103
|
+
# Norway.
|
104
|
+
#
|
105
|
+
country '47', none >> matched_split(/^[1].*$/ => [3], /^[489].*$/ => [3,2,3], :fallback => [2,2,2,2])
|
106
|
+
|
52
107
|
# Poland (Republic of)
|
53
108
|
# Although the NDCs are 2 digits, the representation is 3 digits.
|
54
109
|
# Note: http://wapedia.mobi/en/Telephone_numbers_in_Poland, mobile not yet correct
|
55
110
|
#
|
56
111
|
country '48', fixed(3) >> split(3,3) # Poland
|
57
|
-
# country '49', Phony::Countries::Germany
|
58
112
|
|
59
|
-
country '
|
113
|
+
# country '49' # Germany, see special file.
|
114
|
+
|
115
|
+
# Peru.
|
116
|
+
#
|
117
|
+
country '51', one_of('103', '105') >> split(3,3) | # Service.
|
60
118
|
one_of('1', '9') >> split(4,4) | # Lima and mobile.
|
61
|
-
fixed(2) >> split(4,4)
|
62
|
-
|
119
|
+
fixed(2) >> split(4,4) # 2-digit NDCs.
|
120
|
+
|
121
|
+
# Mexico.
|
122
|
+
#
|
123
|
+
country '52', match(/^(0\d{2})\d+$/) >> split(2,2,2,2) |
|
63
124
|
match(/^(33|55|81)\d+$/) >> split(2,2,2,2) |
|
64
125
|
match(/^(\d{3})\d+$/) >> split(3,2,2)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
country '
|
126
|
+
|
127
|
+
# Cuba.
|
128
|
+
#
|
129
|
+
country '53', match(/^(5\d{3})\d+$/) >> split(4) | # Mobile
|
130
|
+
match(/^(7|21|22|23|4[1-8]|3[1-3])/) >> split(7) | # Short NDCs
|
131
|
+
fixed(3) >> split(7) # 3-digit NDCs
|
132
|
+
|
133
|
+
# TODO Argentine Republic.
|
134
|
+
#
|
135
|
+
country '54', fixed(2) >> split(3,2,2)
|
136
|
+
|
137
|
+
# Brazil (Federative Republic of).
|
138
|
+
#
|
69
139
|
brazilian_service = /^(100|128|190|191|192|193|194|197|198|199)\d+$/
|
70
|
-
country '55', match(brazilian_service) >> split(3,3) | #
|
71
|
-
fixed(2) >> split(4,4)
|
140
|
+
country '55', match(brazilian_service) >> split(3,3) | # Service.
|
141
|
+
fixed(2) >> split(4,4) # NDCs
|
72
142
|
# :service? => brazilian_service, :mobile? => ?
|
73
143
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Brazil
|
74
|
-
# country '56', Phony::Countries::Chile
|
75
|
-
country '57', fixed(2) >> split(3,2,2) # TODO Colombia
|
76
|
-
country '58', fixed(3) >> split(7) # Venezuela (Bolivarian Republic of)
|
77
144
|
|
78
|
-
#
|
79
|
-
|
80
|
-
|
145
|
+
# Chile.
|
146
|
+
#
|
147
|
+
country '56', match(/^(13[0-79]|14[79])\d+$/) >> split(3,3) | # Service
|
148
|
+
one_of('2', '9') >> split(8) | # Santiago, Mobile
|
149
|
+
fixed(2) >> split(8) # 2-digit NDCs
|
150
|
+
|
151
|
+
# TODO Colombia.
|
152
|
+
#
|
153
|
+
country '57', fixed(2) >> split(3,2,2)
|
154
|
+
|
155
|
+
# Venezuela (Bolivarian Republic of)
|
156
|
+
#
|
157
|
+
country '58', fixed(3) >> split(7)
|
158
|
+
|
159
|
+
# country '60' # Malaysia, see special file.
|
160
|
+
|
161
|
+
# Australia.
|
162
|
+
#
|
163
|
+
country '61', match(/^(4\d\d)\d+$/) >> split(3,3) | # Mobile
|
164
|
+
fixed(1) >> split(4,4) # Rest
|
81
165
|
country '62', fixed(2) >> split(3,2,2) # TODO Indonesia (Republic of)
|
82
166
|
country '63', fixed(2) >> split(3,2,2) # TODO Philippines (Republic of the)
|
83
|
-
|
167
|
+
|
168
|
+
# New Zealand.
|
169
|
+
#
|
170
|
+
# TODO Mobile?
|
171
|
+
#
|
172
|
+
country '64', fixed(1) >> split(3,4)
|
173
|
+
|
84
174
|
country '65', fixed(2) >> split(3,2,2) # TODO Singapore (Republic of)
|
85
175
|
country '66', fixed(2) >> split(3,2,2) # TODO Thailand
|
86
176
|
|
87
177
|
country '81', fixed(2) >> split(3,2,2) # TODO Japan
|
88
|
-
|
178
|
+
|
179
|
+
# country '82' # SouthKorea, see special file.
|
180
|
+
|
89
181
|
country '84', fixed(2) >> split(3,2,2) # TODO Viet Nam (Socialist Republic of)
|
90
|
-
# country '86', Phony::Countries::China
|
91
182
|
|
92
|
-
country '
|
183
|
+
# country '86' # China, see special file.
|
184
|
+
|
185
|
+
# Turkey.
|
186
|
+
#
|
187
|
+
country '90', fixed(3) >> split(3,4) # Wiki says 7, but the examples say 3, 4.
|
188
|
+
|
93
189
|
country '91', fixed(2) >> split(3,2,2) # TODO India (Republic of)
|
94
190
|
country '92', fixed(2) >> split(3,2,2) # TODO Pakistan (Islamic Republic of), http://en.wikipedia.org/wiki/Telephone_numbers_in_Pakistan, NDC 2-5
|
95
|
-
|
191
|
+
|
192
|
+
# Afghanistan.
|
193
|
+
#
|
194
|
+
# From http://www.wtng.info/wtng-93-af.html
|
195
|
+
#
|
196
|
+
country '93', fixed(2) >> split(7) # Note: the document says 6, but the examples use 7.
|
96
197
|
|
97
198
|
country '94', fixed(2) >> split(3,2,2) # TODO Sri Lanka (Democratic Socialist Republic of)
|
98
199
|
country '95', fixed(2) >> split(3,2,2) # TODO Myanmar (Union of)
|
@@ -187,27 +288,37 @@ Phony.define do
|
|
187
288
|
country '299', fixed(2) >> split(3,2,2) # Greenland
|
188
289
|
|
189
290
|
country '350', fixed(2) >> split(3,2,2) # Gibraltar
|
190
|
-
|
191
|
-
|
291
|
+
|
292
|
+
# Portugal.
|
293
|
+
#
|
294
|
+
country '351', one_of('700', '800') >> split(3,3) | # Service.
|
295
|
+
match(/^(9\d)\d+$/) >> split(3,4) | # Mobile.
|
192
296
|
one_of('21', '22') >> split(3,4) | # Lisboa & Porto
|
193
|
-
fixed(3) >> split(3,4)
|
297
|
+
fixed(3) >> split(3,4) # 3-digit NDCs
|
298
|
+
|
194
299
|
country '352', fixed(2) >> split(3,2,2) # Luxembourg
|
195
300
|
country '353', fixed(2) >> split(3,2,2) # Ireland (0-3-4)
|
196
301
|
country '354', none >> split(3,4) # Iceland
|
197
302
|
country '355', fixed(2) >> split(3,2,2) # Albania
|
198
303
|
country '356', fixed(2) >> split(3,2,2) # Malta
|
199
304
|
country '357', fixed(2) >> split(3,2,2) # Cyprus
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
305
|
+
|
306
|
+
# Finland.
|
307
|
+
#
|
308
|
+
country '358', match(/^([6-8]00)\d+$/) >> split(3,3) | # Service
|
309
|
+
match(/^(4\d|50)\d+$/) >> split(3,2,2) | # Mobile
|
310
|
+
one_of('2','3','5','6','8','9') >> split(3,3) | # Short NDCs
|
311
|
+
fixed(2) >> split(3,3) # 2-digit NDCs
|
204
312
|
country '359', fixed(2) >> split(3,2,2) # Bulgaria
|
205
313
|
|
206
|
-
|
314
|
+
# Lithuania.
|
315
|
+
#
|
316
|
+
country '370', one_of('700', '800') >> split(2,3) | # Service
|
207
317
|
match(/^(6\d\d)\d+$/) >> split(2,3) | # Mobile
|
208
318
|
one_of('5') >> split(3,2,2) | # Vilnius
|
209
|
-
one_of('37','41') >> split(2,2,2) | #
|
210
|
-
fixed(3) >> split(1,2,2)
|
319
|
+
one_of('37','41') >> split(2,2,2) | # Kaunas, Šiauliai
|
320
|
+
fixed(3) >> split(1,2,2) # 3-digit NDCs.
|
321
|
+
|
211
322
|
country '371', fixed(2) >> split(3,2,2) # Latvia
|
212
323
|
country '372', fixed(2) >> split(3,2,2) # Estonia
|
213
324
|
country '373', fixed(2) >> split(3,2,2) # Moldova
|
@@ -223,17 +334,25 @@ Phony.define do
|
|
223
334
|
country '382', fixed(2) >> split(3,2,2) # -
|
224
335
|
country '383', fixed(2) >> split(3,2,2) # -
|
225
336
|
country '384', fixed(2) >> split(3,2,2) # -
|
226
|
-
|
227
|
-
|
337
|
+
|
338
|
+
# Croatia.
|
339
|
+
#
|
340
|
+
country '385', one_of('1') >> split(3,5) | # Zagreb
|
341
|
+
fixed(2) >> split(3,5) # 2-digit NDCs
|
342
|
+
|
228
343
|
country '386', fixed(2) >> split(3,2,2) # Slovenia
|
229
344
|
country '387', fixed(2) >> split(3,2,2) # Bosnia and Herzegovina
|
230
345
|
country '388', fixed(2) >> split(3,2,2) # Group of countries, shared code
|
231
346
|
country '389', fixed(2) >> split(3,2,2) # The Former Yugoslav Republic of Macedonia
|
232
347
|
|
233
348
|
country '420', fixed(3) >> split(3,3) # Czech Republic
|
234
|
-
|
349
|
+
|
350
|
+
# Slovak Republic.
|
351
|
+
#
|
352
|
+
country '421', match(/^(9\d\d).+$/) >> split(6) | # Mobile
|
235
353
|
one_of('2') >> split(8) | # Bratislava
|
236
|
-
fixed(2) >> split(7)
|
354
|
+
fixed(2) >> split(7) # 2-digit NDCs
|
355
|
+
|
237
356
|
country '422', fixed(2) >> split(3,2,2) # Spare code
|
238
357
|
country '423', none >> split(3,2,2) # Liechtenstein (Principality of)
|
239
358
|
country '424', fixed(2) >> split(3,2,2) # -
|
@@ -15,7 +15,8 @@ mobile = %w{ 10 11 12 13 14 153 154 156 158 16 17 18 19 }
|
|
15
15
|
service = %w{ 100 101 102 103 104 108 112 991 994 995 999 }
|
16
16
|
|
17
17
|
Phony.define do
|
18
|
-
country '60', one_of(service)
|
19
|
-
one_of(mobile)
|
20
|
-
one_of(ndcs
|
18
|
+
country '60', one_of(service) >> split(3,3) | # Service
|
19
|
+
one_of(mobile) >> split(8) | # Mobile
|
20
|
+
one_of(ndcs) >> split(8) | # 1-digit NDCs
|
21
|
+
fixed(2) >> split(8) # 2-digit NDCs
|
21
22
|
end
|
data/lib/phony/country_codes.rb
CHANGED
@@ -1,32 +1,44 @@
|
|
1
1
|
module Phony
|
2
|
-
|
2
|
+
|
3
|
+
EMPTY_STRING = ''
|
4
|
+
|
3
5
|
# Handles determining the correct national code handler.
|
4
6
|
#
|
5
7
|
class CountryCodes
|
6
|
-
|
7
|
-
attr_reader
|
8
|
-
|
8
|
+
|
9
|
+
attr_reader :mapping
|
10
|
+
attr_accessor :international_absolute_format, :international_relative_format, :national_format
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@international_absolute_format = '+%s%s%s%s'
|
14
|
+
@international_relative_format = '00%s%s%s%s'
|
15
|
+
@national_format = '0%s%s'
|
16
|
+
|
17
|
+
@normalize_format = '%s%s'
|
18
|
+
@default_space = ' '
|
19
|
+
end
|
20
|
+
|
9
21
|
def self.instance
|
10
22
|
@instance ||= new
|
11
23
|
end
|
12
|
-
|
24
|
+
|
13
25
|
def normalize number
|
14
26
|
# Remove non-digit chars.
|
15
27
|
#
|
16
|
-
number.gsub! /\D*/,
|
28
|
+
number.gsub! /\D*/, EMPTY_STRING
|
17
29
|
national_handler, cc, rest = split_cc number
|
18
|
-
|
30
|
+
@normalize_format % [cc, national_handler.normalize(rest)]
|
19
31
|
end
|
20
|
-
|
32
|
+
|
21
33
|
# Splits this number into cc, ndc and locally split number parts.
|
22
34
|
#
|
23
35
|
def split number
|
24
36
|
national_handler, cc, rest = split_cc number
|
25
37
|
[cc, *national_handler.split(rest)]
|
26
38
|
end
|
27
|
-
|
39
|
+
|
28
40
|
def formatted number, options = {}
|
29
|
-
format_cc_ndc_local options[:format], options[:spaces] ||
|
41
|
+
format_cc_ndc_local options[:format], options[:spaces] || @default_space, *split(number)
|
30
42
|
end
|
31
43
|
# Formats country code and national destination code.
|
32
44
|
#
|
@@ -34,22 +46,21 @@ module Phony
|
|
34
46
|
"#{format_cc_ndc(format, space, cc, ndc)}#{format_local(space, parts)}"
|
35
47
|
end
|
36
48
|
def format_cc_ndc format, space, cc, ndc
|
37
|
-
|
49
|
+
case format
|
38
50
|
when nil, :international_absolute, :international, :+
|
39
|
-
|
51
|
+
@international_absolute_format % [cc, space, ndc, space]
|
40
52
|
when :international_relative
|
41
|
-
|
53
|
+
@international_relative_format % [cc, space, ndc, space]
|
42
54
|
when :national
|
43
|
-
|
55
|
+
(ndc.empty? ? EMPTY_STRING : @national_format) % [ndc, space]
|
44
56
|
when :local
|
45
|
-
|
57
|
+
EMPTY_STRING
|
46
58
|
end
|
47
|
-
format % split_phone_number
|
48
59
|
end
|
49
60
|
def format_local space, parts_ary
|
50
61
|
parts_ary.join space.to_s
|
51
62
|
end
|
52
|
-
|
63
|
+
|
53
64
|
#
|
54
65
|
#
|
55
66
|
def service? number
|
@@ -64,7 +75,7 @@ module Phony
|
|
64
75
|
national_handler, cc, rest = split_cc number
|
65
76
|
national_handler.landline? rest
|
66
77
|
end
|
67
|
-
|
78
|
+
|
68
79
|
# Is the given number a vanity number?
|
69
80
|
#
|
70
81
|
def vanity? number
|
@@ -77,7 +88,7 @@ module Phony
|
|
77
88
|
national_handler, cc, rest = split_cc vanity_number
|
78
89
|
"#{cc}#{national_handler.vanity_to_number(rest)}"
|
79
90
|
end
|
80
|
-
|
91
|
+
|
81
92
|
def split_cc rest
|
82
93
|
presumed_cc = ''
|
83
94
|
1.upto(3) do |i|
|
@@ -87,25 +98,25 @@ module Phony
|
|
87
98
|
end
|
88
99
|
# This line is never reached as CCs are in prefix code.
|
89
100
|
end
|
90
|
-
|
101
|
+
|
91
102
|
# # TODO
|
92
103
|
# #
|
93
104
|
# def self.with_cc cc
|
94
105
|
# mapping[cc.size][cc.to_s]
|
95
106
|
# end
|
96
|
-
|
107
|
+
|
97
108
|
# Add the given country to the mapping under the
|
98
109
|
# given country code.
|
99
110
|
#
|
100
111
|
def add country_code, country
|
101
112
|
country_code = country_code.to_s
|
102
113
|
optimized_country_code_access = country_code.size
|
103
|
-
|
114
|
+
|
104
115
|
@mapping ||= {}
|
105
116
|
@mapping[optimized_country_code_access] ||= {}
|
106
117
|
@mapping[optimized_country_code_access][country_code] = country
|
107
118
|
end
|
108
|
-
|
119
|
+
|
109
120
|
end
|
110
|
-
|
121
|
+
|
111
122
|
end
|
@@ -28,15 +28,18 @@ describe 'country descriptions' do
|
|
28
28
|
Phony.split('3225551212').should == ['32', '2', '555', '1212'] # Brussels
|
29
29
|
Phony.split('3295551914').should == ['32', '9', '555', '1914'] # Gent
|
30
30
|
Phony.split('3245551414').should == ['32', '4', '555', '1414'] # Liège
|
31
|
+
Phony.split('3216473200').should == ['32', '16', '473', '200'] # Leuven
|
31
32
|
Phony.split('32475279584').should == ['32', '475', '279584'] # mobile
|
33
|
+
Phony.split('3270123123').should == ['32', '70', '123', '123'] # Bus Service?
|
32
34
|
end
|
33
35
|
it 'handles brazilian numbers' do
|
34
36
|
Phony.split('551112341234').should == ['55', '11', '1234', '1234']
|
35
37
|
end
|
36
38
|
it 'handles chilean numbers' do
|
37
|
-
Phony.split('5621234567').should == ['56', '2', '1234567']
|
38
|
-
Phony.split('5675123456').should == ['56', '75', '123456']
|
39
|
-
Phony.split('56912345678').should == ['56', '9', '12345678']
|
39
|
+
Phony.split('5621234567').should == ['56', '2', '1234567'] # Santiago
|
40
|
+
Phony.split('5675123456').should == ['56', '75', '123456'] # Curico
|
41
|
+
Phony.split('56912345678').should == ['56', '9', '12345678'] # Mobile
|
42
|
+
Phony.split('56137123456').should == ['56', '137', '123', '456'] # Service
|
40
43
|
end
|
41
44
|
it 'handles chinese numbers' do
|
42
45
|
Phony.split('862112345678').should == ['86', '21', '1234', '5678'] # Shanghai
|
@@ -83,7 +86,8 @@ describe 'country descriptions' do
|
|
83
86
|
Phony.split('491815878323').should == ['49', '181', '587', '8323'] # Service numbers
|
84
87
|
end
|
85
88
|
it "handles greek numbers" do
|
86
|
-
Phony.split('3021123456').should == ['30', '21', '123456']
|
89
|
+
Phony.split('3021123456').should == ['30', '21', '123456'] # Athens
|
90
|
+
Phony.split('3069512345').should == ['30', '695', '12345'] # Mobile
|
87
91
|
Phony.split('3025941234').should == ['30', '2594', '1234']
|
88
92
|
Phony.split('3022631234').should == ['30', '2263', '1234']
|
89
93
|
end
|
@@ -6,6 +6,46 @@ describe Phony::CountryCodes do
|
|
6
6
|
@countries = Phony::CountryCodes.instance
|
7
7
|
end
|
8
8
|
|
9
|
+
describe 'international_absolute_format=' do
|
10
|
+
it 'formats correctly' do
|
11
|
+
@countries.formatted('41443643532', :format => :international).should == '+41 44 364 35 32'
|
12
|
+
end
|
13
|
+
it 'formats correctly' do
|
14
|
+
old_format = @countries.international_absolute_format
|
15
|
+
@countries.international_absolute_format = '!!! %s%s%s%s'
|
16
|
+
|
17
|
+
@countries.formatted('41443643532', :format => :international).should == '!!! 41 44 364 35 32'
|
18
|
+
|
19
|
+
@countries.international_absolute_format = old_format
|
20
|
+
end
|
21
|
+
end
|
22
|
+
describe 'international_relative_format=' do
|
23
|
+
it 'formats correctly' do
|
24
|
+
@countries.formatted('41443643532', :format => :international_relative).should == '0041 44 364 35 32'
|
25
|
+
end
|
26
|
+
it 'formats correctly' do
|
27
|
+
old_format = @countries.international_relative_format
|
28
|
+
@countries.international_relative_format = '000 %s%s%s%s'
|
29
|
+
|
30
|
+
@countries.formatted('41443643532', :format => :international_relative).should == '000 41 44 364 35 32'
|
31
|
+
|
32
|
+
@countries.international_relative_format = old_format
|
33
|
+
end
|
34
|
+
end
|
35
|
+
describe 'national_format=' do
|
36
|
+
it 'formats correctly' do
|
37
|
+
@countries.formatted('41443643532', :format => :international_relative).should == '0041 44 364 35 32'
|
38
|
+
end
|
39
|
+
it 'formats correctly' do
|
40
|
+
old_format = @countries.national_format
|
41
|
+
@countries.national_format = '%s%s'
|
42
|
+
|
43
|
+
@countries.formatted('11231231234', :format => :national).should == '123 123 1234'
|
44
|
+
|
45
|
+
@countries.national_format = old_format
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
9
49
|
describe 'split' do
|
10
50
|
it 'splits correctly' do
|
11
51
|
@countries.split('41443643532').should == ['41', '44', '364', '35', '32']
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: phony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.4.
|
5
|
+
version: 1.4.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Florian Hanke
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-06 00:00:00 +10:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -24,16 +24,11 @@ extra_rdoc_files:
|
|
24
24
|
- README.textile
|
25
25
|
files:
|
26
26
|
- lib/phony/countries/austria.rb
|
27
|
-
- lib/phony/countries/belgium.rb
|
28
|
-
- lib/phony/countries/chile.rb
|
29
27
|
- lib/phony/countries/china.rb
|
30
28
|
- lib/phony/countries/germany.rb
|
31
|
-
- lib/phony/countries/greece.rb
|
32
|
-
- lib/phony/countries/hungary.rb
|
33
29
|
- lib/phony/countries/italy.rb
|
34
30
|
- lib/phony/countries/malaysia.rb
|
35
31
|
- lib/phony/countries/netherlands.rb
|
36
|
-
- lib/phony/countries/romania.rb
|
37
32
|
- lib/phony/countries/south_korea.rb
|
38
33
|
- lib/phony/countries/sweden.rb
|
39
34
|
- lib/phony/countries/united_kingdom.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# Belgium uses a variable-length ndc code, thus we use a separate file to not let all_other.rb explode.
|
2
|
-
#
|
3
|
-
# Taken from: http://en.wikipedia.org/wiki/Telephone_numbers_in_Belgium
|
4
|
-
#
|
5
|
-
ndcs = [
|
6
|
-
'2', # Brussels (Bruxelles/Brussel)
|
7
|
-
'3', # Antwerpen (Antwerp), Sint-Niklaas
|
8
|
-
'4', # Liège (Luik), Voeren (Fourons)
|
9
|
-
'9', # Gent (Ghent/Gand)
|
10
|
-
]
|
11
|
-
|
12
|
-
mobile_regex = /^(4[789]\d)\d{6}$/ # Mobistar, Base, Proximus
|
13
|
-
|
14
|
-
service = [
|
15
|
-
'70', # Specialty numbers, i.e. bus information or bank information
|
16
|
-
'800', # Tollfree
|
17
|
-
'900', # Premium
|
18
|
-
'901', # Premium
|
19
|
-
'902', # Premium
|
20
|
-
'903', # Premium
|
21
|
-
'904', # Premium
|
22
|
-
'905', # Premium
|
23
|
-
'906', # Premium
|
24
|
-
'907', # Premium
|
25
|
-
'908', # Premium
|
26
|
-
'909' # Premium
|
27
|
-
]
|
28
|
-
|
29
|
-
Phony.define do
|
30
|
-
country '32', one_of(service) >> split(3,3) |
|
31
|
-
match(mobile_regex) >> split(6) |
|
32
|
-
one_of(ndcs, :max_length => 2) >> split(3,5)
|
33
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# Chilean phone numbers.
|
2
|
-
#
|
3
|
-
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Chile
|
4
|
-
# http://www.wtng.info/wtng-56-cl.html
|
5
|
-
#
|
6
|
-
# Note: Totally unsure about this one, as I get contradicting infos (see links above).
|
7
|
-
# As usual, best effort.
|
8
|
-
#
|
9
|
-
service = %w{130 131 132 133 134 135 136 137 139 147 149}
|
10
|
-
|
11
|
-
Phony.define do
|
12
|
-
country '56', one_of(*service) >> split(3,3) |
|
13
|
-
one_of('2', '9', :max_length => 2) >> split(8) # Santiago (2) and mobile.
|
14
|
-
end
|
@@ -1,26 +0,0 @@
|
|
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
|
-
ndcs = [
|
7
|
-
'21', # Athens
|
8
|
-
'231', # Thessaloniki
|
9
|
-
'241', # Larissa
|
10
|
-
'251', # Kavala
|
11
|
-
'261', # Patras
|
12
|
-
'271', # Tripoli
|
13
|
-
'281', # Heraklion
|
14
|
-
'690', # Mobile
|
15
|
-
'693', # Mobile
|
16
|
-
'694', # Mobile
|
17
|
-
'695', # Mobile
|
18
|
-
'697', # Mobile
|
19
|
-
'698', # Mobile
|
20
|
-
'699', # Mobile
|
21
|
-
'800' # Service
|
22
|
-
]
|
23
|
-
|
24
|
-
Phony.define do
|
25
|
-
country '30', one_of(ndcs, :max_length => 4) >> split(6)
|
26
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# Hungarian phone numbers.
|
2
|
-
#
|
3
|
-
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Hungary
|
4
|
-
#
|
5
|
-
|
6
|
-
Phony.define do
|
7
|
-
country '36', one_of('104', '105', '107', '112') >> split(3,3) | # special
|
8
|
-
# TODO mobile
|
9
|
-
one_of('1', :max_length => 2) >> split(3,4)
|
10
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# Romanian phone numbers.
|
2
|
-
#
|
3
|
-
# http://en.wikipedia.org/wiki/Romania_telephone_area_codes
|
4
|
-
#
|
5
|
-
|
6
|
-
ndcs = [
|
7
|
-
'21', # Bucureşti
|
8
|
-
'31', # Bucureşti
|
9
|
-
]
|
10
|
-
mobile = [
|
11
|
-
'71',
|
12
|
-
'72',
|
13
|
-
'73',
|
14
|
-
'74',
|
15
|
-
'75',
|
16
|
-
'76',
|
17
|
-
'77',
|
18
|
-
'78',
|
19
|
-
]
|
20
|
-
service = [
|
21
|
-
'112',
|
22
|
-
'800',
|
23
|
-
'900',
|
24
|
-
'903',
|
25
|
-
'906',
|
26
|
-
]
|
27
|
-
|
28
|
-
Phony.define do
|
29
|
-
country '40', one_of(*service) >> split(3,3) |
|
30
|
-
match(/^(7[1-8])\d*$/) >> split(3,4) |
|
31
|
-
one_of('21', '31', :max_length => 3) >> split(3,4) # Bucureşti
|
32
|
-
end
|