phony 2.18.21 → 2.19.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.textile +1 -1
- data/lib/phony/countries.rb +6 -6
- data/lib/phony/countries/italy.rb +1 -1
- data/lib/phony/countries/japan.rb +7 -6
- data/lib/phony/country.rb +8 -2
- data/lib/phony/country_codes.rb +1 -1
- data/lib/phony/national_code.rb +1 -1
- data/lib/phony/national_splitters/none.rb +1 -3
- data/lib/phony/trunk_code.rb +5 -5
- data/spec/functional/plausibility_spec.rb +10 -1
- data/spec/lib/phony/countries_spec.rb +3 -0
- data/spec/lib/phony/country_codes_spec.rb +43 -45
- data/spec/lib/phony/country_spec.rb +12 -0
- data/spec/lib/phony/trunk_code_spec.rb +85 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54c6578da7427af232e98c6a999e1f53a3bf0098da9a3902d191db28c4d534d7
|
4
|
+
data.tar.gz: 9dac986205602a15d9ccd6ba189dd7fe233664cbbfdc5b7f2cc6c6465648af5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d2f07e5acbe13ad9b8f5c1a034e9c18e73e0915415617a143afc9555b14071084a323016d4866064862cc78fda2b8cb914b5a80762543b15dfaa986e1cbdc23
|
7
|
+
data.tar.gz: bc1397a96d18962582bc2a67628d622503cd972712cd27623ed5b93ec1f4157d7fbf8539dadd6bdeb92dd9d423f5c7a709dca051b4e8e49458f14e418ac452c8
|
data/README.textile
CHANGED
@@ -104,7 +104,7 @@ For example, when just loading the NANP CC, the retained memory usage is ~63kB.
|
|
104
104
|
|
105
105
|
h2. List of Handled Countries
|
106
106
|
|
107
|
-
Mildly unmaintained list: Abhas, Afghan, Algerian, Argentina, Austrian, Australian, Azerbaijani, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, El Salvadorian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Iran, Irish, Israel, Italian, Kazakh, Liberian, Lithuanian, Luxembourgian, Malaysian, Malta, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, Vietnamese, and Zambian numbers.
|
107
|
+
Mildly unmaintained list: Abhas, Afghan, Algerian, Argentina, Austrian, Australian, Azerbaijani, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, El Salvadorian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Iran, Irish, Israel, Italian, Japanese, Kazakh, Liberian, Lithuanian, Luxembourgian, Malaysian, Malta, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, Vietnamese, and Zambian numbers.
|
108
108
|
|
109
109
|
h2. License
|
110
110
|
|
data/lib/phony/countries.rb
CHANGED
@@ -432,9 +432,9 @@ Phony.define do
|
|
432
432
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Rwanda
|
433
433
|
country '250',
|
434
434
|
trunk('0') |
|
435
|
-
one_of('25')
|
436
|
-
match(/^(7[
|
437
|
-
one_of('06')
|
435
|
+
one_of('25') >> split(7) | # Geographic, fixed
|
436
|
+
match(/^(7[2389])/) >> split(7) | # Non-geographic, mobile
|
437
|
+
one_of('06') >> split(6) # Satellite
|
438
438
|
|
439
439
|
country '251', fixed(2) >> split(3, 4) # Ethiopia http://www.wtng.info/wtng-251-et.html
|
440
440
|
|
@@ -486,9 +486,9 @@ Phony.define do
|
|
486
486
|
# http://www.wtng.info/wtng-260-zm.html
|
487
487
|
# https://github.com/googlei18n/libphonenumber/
|
488
488
|
country '260',
|
489
|
-
match(/^(
|
490
|
-
match(/^(800)/)
|
491
|
-
match(/^(21[1-8])/)
|
489
|
+
match(/^([79][5678]\d)/) >> split(6) | # Mobile
|
490
|
+
match(/^(800)/) >> split(3,3) | # Toll free
|
491
|
+
match(/^(21[1-8])/) >> split(6) # Fixed
|
492
492
|
|
493
493
|
# Madagascar http://www.wtng.info/wtng-261-mg.html
|
494
494
|
# http://www.itu.int/oth/T020200007F/en
|
@@ -269,7 +269,7 @@ service = [ # Not exhaustive.
|
|
269
269
|
]
|
270
270
|
|
271
271
|
Phony.define do
|
272
|
-
country '39', trunk('', :
|
272
|
+
country '39', trunk('', normalize: false) |
|
273
273
|
one_of(*service) >> split(3,3) |
|
274
274
|
one_of(*mobile) >> split(3,4,-1..1) |
|
275
275
|
one_of(*ndcs_2digit) >> split(4, 2..4) |
|
@@ -166,6 +166,7 @@ ndcs_with_6_subscriber_numbers = %w(
|
|
166
166
|
422
|
167
167
|
428
|
168
168
|
436
|
169
|
+
438
|
169
170
|
439
|
170
171
|
460
|
171
172
|
463
|
@@ -281,7 +282,6 @@ ndcs_with_6_subscriber_numbers = %w(
|
|
281
282
|
846
|
282
283
|
847
|
283
284
|
848
|
284
|
-
849
|
285
285
|
852
|
286
286
|
853
|
287
287
|
854
|
@@ -361,7 +361,6 @@ ndcs_with_5_subscriber_numbers = %w(
|
|
361
361
|
1374
|
362
362
|
1377
|
363
363
|
1392
|
364
|
-
1394
|
365
364
|
1397
|
366
365
|
1398
|
367
366
|
1456
|
@@ -393,7 +392,6 @@ ndcs_with_5_subscriber_numbers = %w(
|
|
393
392
|
8477
|
394
393
|
8512
|
395
394
|
8514
|
396
|
-
8636
|
397
395
|
9496
|
398
396
|
9802
|
399
397
|
9912
|
@@ -403,12 +401,15 @@ ndcs_with_5_subscriber_numbers = %w(
|
|
403
401
|
|
404
402
|
Phony.define do
|
405
403
|
country '81',
|
406
|
-
trunk('0', :
|
407
|
-
one_of(
|
404
|
+
trunk('0', normalize: true, format: true, split: true) |
|
405
|
+
one_of(%w(20 50 60 70 90)) >> split(4,4) | # mobile, VoIP telephony
|
408
406
|
one_of(ndcs_with_5_subscriber_numbers) >> split(1,4) |
|
409
407
|
one_of(ndcs_with_6_subscriber_numbers) >> split(2,4) |
|
410
408
|
one_of(%w(120)) >> split(3,3) | # freephone
|
411
|
-
one_of(%w(
|
409
|
+
one_of(%w(800)) >> split(3,4) | # freephone
|
410
|
+
one_of(%w(180 570)) >> split(3,3) | # Tele-gong/Tele-dome, Navi-dial
|
411
|
+
one_of(%w(170 990)) >> split(2,4) | # Dengon-dial, Dial Q2 (discontinued)
|
412
|
+
one_of(%w(80)) >> split(4,4) | # mobile
|
412
413
|
one_of(ndcs_with_7_subscriber_numbers) >> split(3,4) |
|
413
414
|
one_of(ndcs_with_8_subscriber_numbers) >> split(4,4) |
|
414
415
|
# TODO: 91(NDC) N(S)N length: 5-13 - Non-geographic number (Direct subscriber telephone service (legacy))
|
data/lib/phony/country.rb
CHANGED
@@ -97,6 +97,9 @@ module Phony
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
def format_cc_ndc trunk, ndc, local, type, space, parentheses, use_trunk
|
100
|
+
# Note: We mark NDCs that are of type "none" with false (nil trips plausible?). This would result in false being printed.
|
101
|
+
# Therefore we set NDC to nil when formatting.
|
102
|
+
ndc = nil if ndc == false
|
100
103
|
case type
|
101
104
|
when String
|
102
105
|
trunk &&= trunk.format(space, use_trunk)
|
@@ -125,6 +128,7 @@ module Phony
|
|
125
128
|
end
|
126
129
|
end
|
127
130
|
def format_ndc ndc, parentheses
|
131
|
+
ndc = nil if ndc == false # TODO
|
128
132
|
parentheses ? "(#{ndc})" : ndc
|
129
133
|
end
|
130
134
|
def format_with_ndc format, cc, ndc, local, space
|
@@ -156,10 +160,12 @@ module Phony
|
|
156
160
|
#
|
157
161
|
# In some cases it doesn't, like Italy.
|
158
162
|
#
|
159
|
-
|
163
|
+
# Note: Options such as CC
|
164
|
+
#
|
165
|
+
def normalize national_number, options = {}
|
160
166
|
clean! national_number
|
161
167
|
normalized = @codes.reduce national_number do |number, code|
|
162
|
-
result = code.normalize number
|
168
|
+
result = code.normalize number, options
|
163
169
|
break result if result
|
164
170
|
number
|
165
171
|
end
|
data/lib/phony/country_codes.rb
CHANGED
data/lib/phony/national_code.rb
CHANGED
@@ -31,9 +31,7 @@ module Phony
|
|
31
31
|
# since using nil is dangerous and breaks
|
32
32
|
# abstraction)
|
33
33
|
#
|
34
|
-
# Note:
|
35
|
-
#
|
36
|
-
# TODO Flip nil/false?
|
34
|
+
# Note: Decided it stays in. When formatting, it's turned into nil.
|
37
35
|
#
|
38
36
|
def split national_number
|
39
37
|
[nil, false, national_number]
|
data/lib/phony/trunk_code.rb
CHANGED
@@ -6,9 +6,9 @@ module Phony
|
|
6
6
|
# * code: The trunk code, e.g. 0.
|
7
7
|
#
|
8
8
|
# Options:
|
9
|
-
# * normalize: Remove the trunk code when normalizing (only use if number scheme is defined unambiguously).
|
10
|
-
# * split: Remove the trunk code when splitting (only use if number scheme is defined unambiguously).
|
11
|
-
# * format: Add the trunk code when formatting (passing `false` will not add it).
|
9
|
+
# * normalize: [true (default), false] Remove the trunk code when normalizing (only use if number scheme is defined unambiguously).
|
10
|
+
# * split: [true, false (default)] Remove the trunk code when splitting (only use if number scheme is defined unambiguously).
|
11
|
+
# * format: [true (default), false] Add the trunk code when formatting (passing `false` will not add it).
|
12
12
|
#
|
13
13
|
def initialize code, options = {}
|
14
14
|
@code = code
|
@@ -35,8 +35,8 @@ module Phony
|
|
35
35
|
|
36
36
|
# Normalize normalizes the given national number.
|
37
37
|
#
|
38
|
-
def normalize national_number
|
39
|
-
national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @normalize
|
38
|
+
def normalize national_number, options = {}
|
39
|
+
national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @normalize && options[:cc]
|
40
40
|
return national_number
|
41
41
|
end
|
42
42
|
|
@@ -255,7 +255,7 @@ describe 'plausibility' do
|
|
255
255
|
end
|
256
256
|
# it_is_correct_for 'Gabonese Republic', :samples => [
|
257
257
|
# '+241 1 627 739',
|
258
|
-
# '+241 12 34 56 78',
|
258
|
+
# '+241 12 34 56 78',
|
259
259
|
# ]
|
260
260
|
it_is_correct_for 'Gambia', :samples => '+220 989 5148'
|
261
261
|
it_is_correct_for 'Germany', :samples => [
|
@@ -399,6 +399,12 @@ describe 'plausibility' do
|
|
399
399
|
'+507 6 123 4567',
|
400
400
|
'+507 2 123 456']
|
401
401
|
it_is_correct_for 'Reunion / Mayotte (new)', :samples => '+262 295 276 964'
|
402
|
+
it_is_correct_for 'Rwanda', :samples => ['+250 72 1234567',
|
403
|
+
'+250 73 1234567',
|
404
|
+
'+250 78 1234567',
|
405
|
+
'+250 79 1234567',
|
406
|
+
'+250 25 1234567',
|
407
|
+
'+250 06 123456']
|
402
408
|
it_is_correct_for 'Saint Helena', :samples => '+290 5134'
|
403
409
|
it_is_correct_for 'Saint Pierre and Miquelon (Collectivité territoriale de la République française)', :samples => '+508 474 714'
|
404
410
|
it_is_correct_for 'Salvador (El)', :samples => [
|
@@ -562,6 +568,9 @@ describe 'plausibility' do
|
|
562
568
|
'+967 58 1234']
|
563
569
|
it 'is correct for Zambia' do
|
564
570
|
Phony.plausible?('+260 211 123456').should be_truthy # Fixed
|
571
|
+
Phony.plausible?('+260 761 123456').should be_truthy # Mobile
|
572
|
+
Phony.plausible?('+260 772 123456').should be_truthy # Mobile
|
573
|
+
Phony.plausible?('+260 783 123456').should be_truthy # Mobile
|
565
574
|
Phony.plausible?('+260 955 123456').should be_truthy # Mobile
|
566
575
|
Phony.plausible?('+260 967 123456').should be_truthy # Mobile
|
567
576
|
Phony.plausible?('+260 978 123456').should be_truthy # Mobile
|
@@ -484,6 +484,8 @@ describe 'country descriptions' do
|
|
484
484
|
it_splits '817012345678', %w(81 70 1234 5678) # PHS
|
485
485
|
it_splits '818012345678', %w(81 80 1234 5678) # Cellular
|
486
486
|
it_splits '819012345678', %w(81 90 1234 5678) # Cellular
|
487
|
+
it_splits '810570123456', %w(81 570 123 456) # Navi-dial
|
488
|
+
it_splits '810180123456', %w(81 180 123 456) # Tele-gong/Tele-dome
|
487
489
|
end
|
488
490
|
describe 'Kenya' do
|
489
491
|
it_splits '254201234567', ['254', '20', '1234567'] # Nairobi
|
@@ -677,6 +679,7 @@ describe 'country descriptions' do
|
|
677
679
|
it_splits '250781234567', ['250', '78', '1234567'] # mobile
|
678
680
|
it_splits '250721234567', ['250', '72', '1234567'] # mobile
|
679
681
|
it_splits '250731234567', ['250', '73', '1234567'] # mobile
|
682
|
+
it_splits '250791234567', ['250', '79', '1234567'] # mobile
|
680
683
|
it_splits '250251234567', ['250', '25', '1234567'] # fixed
|
681
684
|
it_splits '25006123456', ['250', '06', '123456'] # fixed
|
682
685
|
end
|
@@ -1,32 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Phony::CountryCodes do
|
4
|
-
|
5
|
-
|
6
|
-
@countries = Phony::CountryCodes.instance
|
7
|
-
end
|
4
|
+
|
5
|
+
let(:countries) { Phony::CountryCodes.instance }
|
8
6
|
|
9
7
|
describe '#[]' do
|
10
8
|
it 'returns a country' do
|
11
|
-
|
9
|
+
countries['41'].class.should eql Phony::Country
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
13
|
describe '#country_for' do
|
16
14
|
it 'returns a country' do
|
17
|
-
|
15
|
+
countries.send(:country_for, '41').class.should eql Phony::Country
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
21
19
|
describe '#countrify' do
|
22
20
|
it 'returns a country' do
|
23
|
-
|
21
|
+
countries.send(:countrify, '441231212', '41').should eql '41441231212'
|
24
22
|
end
|
25
23
|
end
|
26
24
|
describe '#countrify!' do
|
27
25
|
it 'in-place replaces the number' do
|
28
26
|
number = '441231212'
|
29
|
-
|
27
|
+
countries.send(:countrify!, number, '41').should eql number
|
30
28
|
|
31
29
|
number.should == '41441231212'
|
32
30
|
end
|
@@ -34,127 +32,127 @@ describe Phony::CountryCodes do
|
|
34
32
|
|
35
33
|
describe '#vanity?' do
|
36
34
|
it 'returns true if so' do
|
37
|
-
|
35
|
+
countries.vanity?('1800HELLOES').should eql true
|
38
36
|
end
|
39
37
|
it 'returns false if not' do
|
40
|
-
|
38
|
+
countries.vanity?('18001234567').should eql false
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
44
42
|
describe 'normalize' do
|
45
43
|
it 'normalizes correctly' do
|
46
|
-
|
44
|
+
countries.normalize('0041-44-364-35-32').should eql '41443643532'
|
47
45
|
end
|
48
46
|
it 'normalizes correctly with CC option' do
|
49
|
-
|
47
|
+
countries.normalize('044-364-35-32', cc: '41').should eql '41443643532'
|
50
48
|
end
|
51
49
|
|
52
50
|
context 'specific countries' do
|
53
51
|
it 'handles Congo correctly' do
|
54
|
-
|
55
|
-
|
52
|
+
countries.normalize('+242 0571 73992').should eql '242057173992'
|
53
|
+
countries.normalize('+242 2221 15932').should eql '242222115932'
|
56
54
|
end
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
60
58
|
describe 'formatted' do
|
61
59
|
it 'formats correctly' do
|
62
|
-
|
60
|
+
countries.formatted('41443643532', :format => :international, :spaces => :-).should eql '+41-44-364-35-32'
|
63
61
|
end
|
64
62
|
it 'formats correctly' do
|
65
|
-
|
63
|
+
countries.formatted('41443643532', :format => :international_relative, :spaces => :-).should eql '0041-44-364-35-32'
|
66
64
|
end
|
67
65
|
it 'formats correctly' do
|
68
|
-
|
66
|
+
countries.formatted('41443643532', :format => :national, :spaces => :-).should eql '044-364-35-32'
|
69
67
|
end
|
70
68
|
context 'specific' do
|
71
69
|
it 'formats Ireland correctly' do
|
72
|
-
|
70
|
+
countries.formatted("3533451234", :format => :national).should eql '0345 1234'
|
73
71
|
end
|
74
72
|
it 'formats Ireland correctly' do
|
75
|
-
|
73
|
+
countries.formatted("353411231234", :format => :national).should eql '041 123 1234'
|
76
74
|
end
|
77
75
|
it 'formats Spain correctly' do
|
78
|
-
|
76
|
+
countries.formatted("34123456789", :format => :national).should eql '123 456 789'
|
79
77
|
end
|
80
78
|
it 'formats Cambodia correctly' do
|
81
|
-
|
79
|
+
countries.formatted('85512239123', :format => :national).should eql '012 239 123'
|
82
80
|
end
|
83
81
|
it 'formats the US correctly' do
|
84
|
-
|
82
|
+
countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
|
85
83
|
end
|
86
84
|
it 'formats the US correctly' do
|
87
|
-
|
85
|
+
countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
|
88
86
|
end
|
89
87
|
end
|
90
88
|
context 'default' do
|
91
89
|
it "should format swiss numbers" do
|
92
|
-
|
90
|
+
countries.formatted('41443643532').should eql '+41 44 364 35 32'
|
93
91
|
end
|
94
92
|
it "should format swiss service numbers" do
|
95
|
-
|
93
|
+
countries.formatted('41800112233').should eql '+41 800 112 233'
|
96
94
|
end
|
97
95
|
it "should format austrian numbers" do
|
98
|
-
|
96
|
+
countries.formatted('43198110').should eql '+43 1 98110'
|
99
97
|
end
|
100
98
|
it "should format american numbers" do
|
101
|
-
|
99
|
+
countries.formatted('18705551122').should eql '+1 (870) 555-1122'
|
102
100
|
end
|
103
101
|
it "should format irish numbers" do
|
104
|
-
|
102
|
+
countries.formatted('35311234567').should eql '+353 1 123 4567'
|
105
103
|
end
|
106
104
|
end
|
107
105
|
describe "international" do
|
108
106
|
it "should format north american numbers" do
|
109
|
-
|
107
|
+
countries.formatted('18091231234', :format => :international).should eql '+1 (809) 123-1234'
|
110
108
|
end
|
111
109
|
it "should format austrian numbers" do
|
112
|
-
|
110
|
+
countries.formatted('43198110', :format => :international).should eql '+43 1 98110'
|
113
111
|
end
|
114
112
|
it "should format austrian numbers" do
|
115
|
-
|
113
|
+
countries.formatted('43198110', :format => :international_absolute).should eql '+43 1 98110'
|
116
114
|
end
|
117
115
|
it "should format french numbers" do
|
118
|
-
|
116
|
+
countries.formatted('33142278186', :format => :+).should eql '+33 1 42 27 81 86'
|
119
117
|
end
|
120
118
|
it "should format austrian numbers" do
|
121
|
-
|
119
|
+
countries.formatted('43198110', :format => :international_relative).should eql '0043 1 98110'
|
122
120
|
end
|
123
121
|
it 'should format liechtensteiner numbers' do
|
124
|
-
|
122
|
+
countries.formatted('4233841148', :format => :international_relative).should eql '00423 384 11 48'
|
125
123
|
end
|
126
124
|
it "should format irish numbers" do
|
127
|
-
|
125
|
+
countries.formatted('35311234567', :format => :international).should eql '+353 1 123 4567'
|
128
126
|
end
|
129
127
|
it "should format luxembourgian numbers" do
|
130
|
-
|
128
|
+
countries.formatted('352222809', :format => :international).should eql '+352 22 28 09'
|
131
129
|
end
|
132
130
|
it "should format luxembourgian 4-digit ndc numbers" do
|
133
|
-
|
131
|
+
countries.formatted('35226222809', :format => :international).should eql '+352 2622 28 09'
|
134
132
|
end
|
135
133
|
it "should format luxembourgian mobile numbers" do
|
136
|
-
|
134
|
+
countries.formatted('352621123456', :format => :international).should eql '+352 621 123 456'
|
137
135
|
end
|
138
136
|
it "should format luxembourgian city numbers" do
|
139
|
-
|
137
|
+
countries.formatted('3524123456', :format => :international).should eql '+352 41 23 45 6'
|
140
138
|
end
|
141
139
|
it "should format luxembourgian machine to machine numbers" do
|
142
|
-
|
140
|
+
countries.formatted('352602112345678', :format => :international).should eql '+352 6021 12 34 56 78'
|
143
141
|
end
|
144
142
|
it "should format luxembourgian numbers" do
|
145
|
-
|
143
|
+
countries.formatted('352370431', :format => :international).should eql '+352 37 04 31'
|
146
144
|
end
|
147
145
|
it "should format luxembourgian numbers" do
|
148
|
-
|
146
|
+
countries.formatted('35227855', :format => :international).should eql '+352 27 85 5'
|
149
147
|
end
|
150
148
|
it "should format nigerian lagosian numbers" do
|
151
|
-
|
149
|
+
countries.formatted('23414480000', :format => :international).should eql '+234 1 448 0000'
|
152
150
|
end
|
153
151
|
it "should format nigerian beninese numbers" do
|
154
|
-
|
152
|
+
countries.formatted('23452123456', :format => :international).should eql '+234 52 123 456'
|
155
153
|
end
|
156
154
|
it "should format nigerian mobile numbers" do
|
157
|
-
|
155
|
+
countries.formatted('2347061234567', :format => :international).should eql '+234 706 123 4567'
|
158
156
|
end
|
159
157
|
context 'with no spaces' do
|
160
158
|
it "should format north american numbers" do
|
@@ -43,6 +43,18 @@ describe Phony::Country do
|
|
43
43
|
Phony.normalize('+378903549').should == '3780549903549'
|
44
44
|
end
|
45
45
|
end
|
46
|
+
describe 'Japan' do
|
47
|
+
it 'normalizes correctly' do
|
48
|
+
Phony.normalize('+81-03-1234-5634').should == '81312345634'
|
49
|
+
Phony.normalize('03-1234-5634', cc: '81').should == '81312345634'
|
50
|
+
end
|
51
|
+
it 'formats correctly' do
|
52
|
+
Phony.format('81312345634').should == '+81-3-1234-5634'
|
53
|
+
end
|
54
|
+
it 'splits correctly' do
|
55
|
+
Phony.split('81312345634').should == %w(81 3 1234 5634)
|
56
|
+
end
|
57
|
+
end
|
46
58
|
end
|
47
59
|
|
48
60
|
context "without special cases (with switzerland)" do
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Phony::TrunkCode do
|
4
|
+
|
5
|
+
describe '#format' do
|
6
|
+
it 'is correct' do
|
7
|
+
code = described_class.new('0')
|
8
|
+
expect(code.format('%s %s')).to eq '0'
|
9
|
+
end
|
10
|
+
it 'is correct' do
|
11
|
+
code = described_class.new('0', format: true)
|
12
|
+
expect(code.format('%s %s')).to eq '0'
|
13
|
+
end
|
14
|
+
it 'is correct' do
|
15
|
+
code = described_class.new('0', format: false)
|
16
|
+
expect(code.format('%s %s')).to eq nil
|
17
|
+
end
|
18
|
+
it 'is correct' do
|
19
|
+
code = described_class.new('06')
|
20
|
+
expect(code.format('%s %s')).to eq '06'
|
21
|
+
end
|
22
|
+
it 'is correct' do
|
23
|
+
code = described_class.new('06', format: true)
|
24
|
+
expect(code.format('%s %s')).to eq '06'
|
25
|
+
end
|
26
|
+
it 'is correct' do
|
27
|
+
code = described_class.new('06', format: false)
|
28
|
+
expect(code.format('%s %s')).to eq nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#normalize' do
|
33
|
+
it 'is correct' do
|
34
|
+
code = described_class.new('0')
|
35
|
+
expect(code.normalize('0123')).to eq '0123'
|
36
|
+
end
|
37
|
+
it 'is correct' do
|
38
|
+
code = described_class.new('0', normalize: true)
|
39
|
+
expect(code.normalize('0123')).to eq '0123'
|
40
|
+
end
|
41
|
+
it 'is correct' do
|
42
|
+
code = described_class.new('0', normalize: false)
|
43
|
+
expect(code.normalize('0123')).to eq '0123'
|
44
|
+
end
|
45
|
+
it 'is correct' do
|
46
|
+
code = described_class.new('06')
|
47
|
+
expect(code.normalize('06123')).to eq '06123'
|
48
|
+
end
|
49
|
+
it 'is correct' do
|
50
|
+
code = described_class.new('06', normalize: true)
|
51
|
+
expect(code.normalize('06123')).to eq '06123'
|
52
|
+
end
|
53
|
+
it 'is correct' do
|
54
|
+
code = described_class.new('06', normalize: false)
|
55
|
+
expect(code.normalize('0123')).to eq '0123'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#split' do
|
60
|
+
it 'is correct' do
|
61
|
+
code = described_class.new('0')
|
62
|
+
expect(code.split('0123')).to eq [code, '0123']
|
63
|
+
end
|
64
|
+
it 'is correct' do
|
65
|
+
code = described_class.new('0', split: true)
|
66
|
+
expect(code.split('0123')).to eq [code, '123']
|
67
|
+
end
|
68
|
+
it 'is correct' do
|
69
|
+
code = described_class.new('0', split: false)
|
70
|
+
expect(code.split('0123')).to eq [code, '0123']
|
71
|
+
end
|
72
|
+
it 'is correct' do
|
73
|
+
code = described_class.new('06')
|
74
|
+
expect(code.split('06123')).to eq [code, '06123']
|
75
|
+
end
|
76
|
+
it 'is correct' do
|
77
|
+
code = described_class.new('06', split: true)
|
78
|
+
expect(code.split('06123')).to eq [code, '123']
|
79
|
+
end
|
80
|
+
it 'is correct' do
|
81
|
+
code = described_class.new('06', split: false)
|
82
|
+
expect(code.split('06123')).to eq [code, '06123']
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.19.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Hanke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Fast international phone number (E164 standard) normalizing, splitting
|
14
14
|
and formatting. Lots of formatting options: International (+.., 00..), national
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- spec/lib/phony/national_splitters/none_spec.rb
|
94
94
|
- spec/lib/phony/national_splitters/regex_spec.rb
|
95
95
|
- spec/lib/phony/national_splitters/variable_spec.rb
|
96
|
+
- spec/lib/phony/trunk_code_spec.rb
|
96
97
|
- spec/lib/phony/vanity_spec.rb
|
97
98
|
- spec/lib/phony_spec.rb
|
98
99
|
homepage: https://github.com/floere/phony
|
@@ -121,6 +122,7 @@ summary: Fast international phone number (E164 standard) normalizing, splitting
|
|
121
122
|
formatting.
|
122
123
|
test_files:
|
123
124
|
- spec/lib/phony_spec.rb
|
125
|
+
- spec/lib/phony/trunk_code_spec.rb
|
124
126
|
- spec/lib/phony/country_spec.rb
|
125
127
|
- spec/lib/phony/national_code_spec.rb
|
126
128
|
- spec/lib/phony/countries_spec.rb
|