phony 1.2.0 → 1.2.1
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.
@@ -118,9 +118,11 @@ module Phony
|
|
118
118
|
'84' => fixed(2), # TODO Viet Nam (Socialist Republic of)
|
119
119
|
'86' => fixed(2), # TODO China (People's Republic of)
|
120
120
|
|
121
|
-
'90' => fixed(
|
121
|
+
'90' => fixed(3, # Turkey, http://en.wikipedia.org/wiki/Telephone_numbers_in_Turkey
|
122
|
+
:local_format => [3, 4] # Wiki says 7, but the examples say 3, 4.
|
123
|
+
),
|
122
124
|
'91' => fixed(2), # TODO India (Republic of)
|
123
|
-
'92' => fixed(2), # TODO Pakistan (Islamic Republic of)
|
125
|
+
'92' => fixed(2), # TODO Pakistan (Islamic Republic of), http://en.wikipedia.org/wiki/Telephone_numbers_in_Pakistan, NDC 2-5
|
124
126
|
'93' => fixed(2, # Afghanistan
|
125
127
|
:local_format => [7] # Actually, the document says 6, but the examples use 7.
|
126
128
|
), # http://www.wtng.info/wtng-93-af.html
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Chile
|
4
4
|
# http://www.wtng.info/wtng-56-cl.html
|
5
5
|
#
|
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
9
|
Phony::Countries::Chile = Phony::Country.configured :local_format => [8],
|
@@ -39,10 +39,10 @@ Phony::Countries::Netherlands = Phony::Country.configured :local_format => [8],
|
|
39
39
|
'78', # Dordrecht
|
40
40
|
'79', # Zoetermeer
|
41
41
|
],
|
42
|
-
:mobile => [
|
42
|
+
:mobile => [
|
43
43
|
'6' # Mobiele nummers en Semafoondiensten
|
44
44
|
],
|
45
|
-
:service => [
|
45
|
+
:service => [
|
46
46
|
'84', # Persoonlijke-assistentdiensten, zoals voicemail en faxmail
|
47
47
|
'85', # Plaatsonafhankelijk netnummer
|
48
48
|
'87', # Both of the above.
|
data/lib/phony/country_codes.rb
CHANGED
@@ -26,9 +26,7 @@ module Phony
|
|
26
26
|
def format_cc_ndc_local format, space, cc, ndc, *parts
|
27
27
|
"#{format_cc_ndc(format, space, cc, ndc)}#{format_local(space, parts)}"
|
28
28
|
end
|
29
|
-
|
30
|
-
#
|
31
|
-
def format_cc_ndc format, space, cc, ndc = ''
|
29
|
+
def format_cc_ndc format, space, cc, ndc
|
32
30
|
format, split_phone_number = case format
|
33
31
|
when nil, :international_absolute, :international, :+
|
34
32
|
[ndc.empty? ? '+%s%s' : '+%s%s%s%s', [cc, space, ndc, space]]
|
@@ -45,8 +43,6 @@ module Phony
|
|
45
43
|
parts_ary.join space.to_s
|
46
44
|
end
|
47
45
|
|
48
|
-
# TODO Speed these methods up.
|
49
|
-
#
|
50
46
|
def service? number
|
51
47
|
national_handler, cc, rest = split_cc number
|
52
48
|
national_handler.service? rest
|
@@ -80,7 +76,7 @@ module Phony
|
|
80
76
|
national_code_handler = mapping[i][presumed_cc]
|
81
77
|
return [national_code_handler, presumed_cc, rest] if national_code_handler
|
82
78
|
end
|
83
|
-
#
|
79
|
+
# This line is never reached as CCs are in prefix code.
|
84
80
|
end
|
85
81
|
|
86
82
|
# Removes 0s from partially normalized numbers
|
@@ -88,6 +84,7 @@ module Phony
|
|
88
84
|
#
|
89
85
|
# Example:
|
90
86
|
# 410443643533 -> 41443643533
|
87
|
+
#
|
91
88
|
def remove_relative_zeros! phone_number
|
92
89
|
_, cc, rest = split_cc phone_number
|
93
90
|
'%s%s' % [cc, rest].collect! { |code| code.gsub(/^0+/, '') }
|
@@ -26,7 +26,7 @@ describe Phony::LocalSplitter do
|
|
26
26
|
@splitter.split('3643532111').should == ['364','35','32']
|
27
27
|
end
|
28
28
|
it 'splits correctly even when the number is too short' do
|
29
|
-
@splitter.split('364353').should == ['364','35','3']
|
29
|
+
@splitter.split('364353').should == ['364','35','3']
|
30
30
|
end
|
31
31
|
end
|
32
32
|
context "with format" do
|
@@ -40,7 +40,7 @@ describe Phony::LocalSplitter do
|
|
40
40
|
@splitter.split('3643532111').should == ['364','35','32']
|
41
41
|
end
|
42
42
|
it 'splits correctly even when the number is too short' do
|
43
|
-
@splitter.split('364353').should == ['364','35','3']
|
43
|
+
@splitter.split('364353').should == ['364','35','3']
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
data/spec/lib/phony_spec.rb
CHANGED
@@ -73,6 +73,9 @@ describe Phony do
|
|
73
73
|
it "should handle swiss numbers" do
|
74
74
|
Phony.split('41443643532').should == ['41', '44', '364', '35', '32']
|
75
75
|
end
|
76
|
+
it 'handles turkish numbers' do
|
77
|
+
Phony.split('903121234567').should == ['90', '312', '123', '4567'] # Ankara
|
78
|
+
end
|
76
79
|
it "should handle US numbers" do
|
77
80
|
Phony.split('15551115511').should == ['1', '555', '111', '5511']
|
78
81
|
end
|
@@ -229,6 +232,36 @@ describe Phony do
|
|
229
232
|
end
|
230
233
|
end
|
231
234
|
|
235
|
+
context 'minimal cases' do
|
236
|
+
context 'normalizing' do
|
237
|
+
it 'handles completely crazy "numbers"' do
|
238
|
+
Phony.normalize('Hello, I am Cora, the 41th parrot, and 044 is my 364 times 35 funky number. 32.').should == '41443643532'
|
239
|
+
end
|
240
|
+
end
|
241
|
+
context 'splitting' do
|
242
|
+
it 'handles completely missing numbers well enough' do
|
243
|
+
Phony.split('4144').should == ['41', '44', '']
|
244
|
+
end
|
245
|
+
it 'handles a missing number part' do
|
246
|
+
Phony.split('4144364').should == ['41', '44', '364']
|
247
|
+
end
|
248
|
+
it 'handles a missing number part' do
|
249
|
+
Phony.split('414436435').should == ['41', '44', '364', '35']
|
250
|
+
end
|
251
|
+
end
|
252
|
+
context 'formatting' do
|
253
|
+
it 'handles completely missing numbers well enough' do
|
254
|
+
Phony.formatted('4144').should == '+41 44 '
|
255
|
+
end
|
256
|
+
it 'handles a missing number part' do
|
257
|
+
Phony.formatted('4144364').should == '+41 44 364'
|
258
|
+
end
|
259
|
+
it 'handles a missing number part' do
|
260
|
+
Phony.formatted('414436435').should == '+41 44 364 35'
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
232
265
|
context "speed" do
|
233
266
|
before(:each) do
|
234
267
|
@phone_numbers = [
|
@@ -268,20 +301,6 @@ describe Phony do
|
|
268
301
|
end
|
269
302
|
end
|
270
303
|
|
271
|
-
# describe "service?" do
|
272
|
-
#
|
273
|
-
# end
|
274
|
-
# describe "mobile?" do
|
275
|
-
# # TODO Test dirty numbers.
|
276
|
-
# #
|
277
|
-
# it 'is correct' do
|
278
|
-
# Phony.mobile?('49172123456').should == true
|
279
|
-
# end
|
280
|
-
# it 'is correct' do
|
281
|
-
# Phony.mobile?('12172123456').should == false
|
282
|
-
# end
|
283
|
-
# end
|
284
|
-
|
285
304
|
describe 'vanity' do
|
286
305
|
describe 'vanity_number?' do
|
287
306
|
it {Phony.vanity?('41800 WEGGLI').should be_true}
|