phony 2.16.4 → 2.20.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.textile +34 -6
- data/lib/phony/config.rb +91 -0
- data/lib/phony/countries/argentina.rb +355 -0
- data/lib/phony/countries/austria.rb +4 -2
- data/lib/phony/countries/bangladesh.rb +2 -0
- data/lib/phony/countries/belarus.rb +2 -0
- data/lib/phony/countries/brazil.rb +4 -2
- data/lib/phony/countries/cambodia.rb +3 -5
- data/lib/phony/countries/china.rb +7 -2
- data/lib/phony/countries/croatia.rb +2 -0
- data/lib/phony/countries/georgia.rb +2 -0
- data/lib/phony/countries/germany.rb +5 -2
- data/lib/phony/countries/guinea.rb +8 -5
- data/lib/phony/countries/india.rb +2 -0
- data/lib/phony/countries/indonesia.rb +2 -0
- data/lib/phony/countries/ireland.rb +27 -23
- data/lib/phony/countries/italy.rb +40 -18
- data/lib/phony/countries/japan.rb +61 -8
- data/lib/phony/countries/kyrgyzstan.rb +2 -0
- data/lib/phony/countries/latvia.rb +2 -0
- data/lib/phony/countries/libya.rb +3 -1
- data/lib/phony/countries/malaysia.rb +22 -2
- data/lib/phony/countries/moldova.rb +2 -0
- data/lib/phony/countries/montenegro.rb +2 -0
- data/lib/phony/countries/myanmar.rb +2 -0
- data/lib/phony/countries/namibia.rb +2 -0
- data/lib/phony/countries/nepal.rb +2 -0
- data/lib/phony/countries/netherlands.rb +2 -0
- data/lib/phony/countries/pakistan.rb +2 -0
- data/lib/phony/countries/paraguay.rb +2 -0
- data/lib/phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb +22 -13
- data/lib/phony/countries/saudi_arabia.rb +2 -0
- data/lib/phony/countries/serbia.rb +7 -1
- data/lib/phony/countries/somalia.rb +2 -0
- data/lib/phony/countries/south_korea.rb +7 -2
- data/lib/phony/countries/sweden.rb +2 -0
- data/lib/phony/countries/taiwan.rb +3 -0
- data/lib/phony/countries/tajikistan.rb +2 -0
- data/lib/phony/countries/turkmenistan.rb +2 -0
- data/lib/phony/countries/ukraine.rb +3 -0
- data/lib/phony/countries/united_kingdom.rb +5 -2
- data/lib/phony/countries/uruguay.rb +2 -0
- data/lib/phony/countries/vietnam.rb +93 -93
- data/lib/phony/countries/zimbabwe.rb +2 -0
- data/lib/phony/countries.rb +142 -64
- data/lib/phony/country.rb +15 -3
- data/lib/phony/country_codes.rb +16 -3
- data/lib/phony/dsl.rb +5 -3
- data/lib/phony/local_splitters/fixed.rb +2 -0
- 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/lib/phony.rb +62 -57
- data/spec/functional/config_spec.rb +44 -0
- data/spec/functional/plausibility_spec.rb +285 -18
- data/spec/lib/phony/countries_spec.rb +140 -39
- data/spec/lib/phony/country_codes_spec.rb +82 -58
- data/spec/lib/phony/country_spec.rb +29 -9
- data/spec/lib/phony/dsl_spec.rb +7 -3
- data/spec/lib/phony/local_splitters/regex_spec.rb +19 -15
- data/spec/lib/phony/national_code_spec.rb +15 -45
- data/spec/lib/phony/national_splitters/fixed_spec.rb +12 -16
- data/spec/lib/phony/national_splitters/none_spec.rb +3 -3
- data/spec/lib/phony/national_splitters/variable_spec.rb +9 -13
- data/spec/lib/phony/trunk_code_spec.rb +85 -0
- data/spec/lib/phony/vanity_spec.rb +4 -4
- data/spec/lib/phony_spec.rb +63 -67
- metadata +13 -8
data/lib/phony.rb
CHANGED
@@ -1,70 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# NOTE We use Kernel.load here, as it's possible to redefine Phony via Phony::Config.
|
4
|
+
|
1
5
|
# Framework.
|
2
6
|
#
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
load File.expand_path '../phony/config.rb', __FILE__
|
8
|
+
load File.expand_path '../phony/vanity.rb', __FILE__
|
9
|
+
load File.expand_path '../phony/local_splitters/fixed.rb', __FILE__
|
10
|
+
load File.expand_path '../phony/local_splitters/regex.rb', __FILE__
|
11
|
+
load File.expand_path '../phony/national_splitters/dsl.rb', __FILE__
|
12
|
+
load File.expand_path '../phony/national_splitters/fixed.rb', __FILE__
|
13
|
+
load File.expand_path '../phony/national_splitters/variable.rb', __FILE__
|
14
|
+
load File.expand_path '../phony/national_splitters/regex.rb', __FILE__
|
15
|
+
load File.expand_path '../phony/national_splitters/default.rb', __FILE__
|
16
|
+
load File.expand_path '../phony/national_splitters/none.rb', __FILE__
|
17
|
+
load File.expand_path '../phony/national_code.rb', __FILE__
|
18
|
+
load File.expand_path '../phony/country.rb', __FILE__
|
19
|
+
load File.expand_path '../phony/trunk_code.rb', __FILE__
|
20
|
+
load File.expand_path '../phony/country_codes.rb', __FILE__
|
21
|
+
load File.expand_path '../phony/dsl.rb', __FILE__
|
18
22
|
|
19
23
|
# Countries.
|
20
24
|
#
|
21
25
|
# The ones that need more space to define.
|
22
26
|
#
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
27
|
+
load File.expand_path '../phony/countries/argentina.rb', __FILE__
|
28
|
+
load File.expand_path '../phony/countries/austria.rb', __FILE__
|
29
|
+
load File.expand_path '../phony/countries/bangladesh.rb', __FILE__
|
30
|
+
load File.expand_path '../phony/countries/belarus.rb', __FILE__
|
31
|
+
load File.expand_path '../phony/countries/brazil.rb', __FILE__
|
32
|
+
load File.expand_path '../phony/countries/cambodia.rb', __FILE__
|
33
|
+
load File.expand_path '../phony/countries/croatia.rb', __FILE__
|
34
|
+
load File.expand_path '../phony/countries/china.rb', __FILE__
|
35
|
+
load File.expand_path '../phony/countries/georgia.rb', __FILE__
|
36
|
+
load File.expand_path '../phony/countries/germany.rb', __FILE__
|
37
|
+
load File.expand_path '../phony/countries/guinea.rb', __FILE__
|
38
|
+
load File.expand_path '../phony/countries/india.rb', __FILE__
|
39
|
+
load File.expand_path '../phony/countries/indonesia.rb', __FILE__
|
40
|
+
load File.expand_path '../phony/countries/ireland.rb', __FILE__
|
41
|
+
load File.expand_path '../phony/countries/italy.rb', __FILE__
|
42
|
+
load File.expand_path '../phony/countries/japan.rb', __FILE__
|
43
|
+
load File.expand_path '../phony/countries/kyrgyzstan.rb', __FILE__
|
44
|
+
load File.expand_path '../phony/countries/latvia.rb', __FILE__
|
45
|
+
load File.expand_path '../phony/countries/libya.rb', __FILE__
|
46
|
+
load File.expand_path '../phony/countries/malaysia.rb', __FILE__
|
47
|
+
load File.expand_path '../phony/countries/moldova.rb', __FILE__
|
48
|
+
load File.expand_path '../phony/countries/montenegro.rb', __FILE__
|
49
|
+
load File.expand_path '../phony/countries/myanmar.rb', __FILE__
|
50
|
+
load File.expand_path '../phony/countries/namibia.rb', __FILE__
|
51
|
+
load File.expand_path '../phony/countries/nepal.rb', __FILE__
|
52
|
+
load File.expand_path '../phony/countries/netherlands.rb', __FILE__
|
53
|
+
load File.expand_path '../phony/countries/pakistan.rb', __FILE__
|
54
|
+
load File.expand_path '../phony/countries/paraguay.rb', __FILE__
|
55
|
+
load File.expand_path '../phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb', __FILE__
|
56
|
+
load File.expand_path '../phony/countries/saudi_arabia.rb', __FILE__
|
57
|
+
load File.expand_path '../phony/countries/serbia.rb', __FILE__
|
58
|
+
load File.expand_path '../phony/countries/somalia.rb', __FILE__
|
59
|
+
load File.expand_path '../phony/countries/south_korea.rb', __FILE__
|
60
|
+
load File.expand_path '../phony/countries/sweden.rb', __FILE__
|
61
|
+
load File.expand_path '../phony/countries/taiwan.rb', __FILE__
|
62
|
+
load File.expand_path '../phony/countries/tajikistan.rb', __FILE__
|
63
|
+
load File.expand_path '../phony/countries/turkmenistan.rb', __FILE__
|
64
|
+
load File.expand_path '../phony/countries/vietnam.rb', __FILE__
|
65
|
+
load File.expand_path '../phony/countries/ukraine.rb', __FILE__
|
66
|
+
load File.expand_path '../phony/countries/united_kingdom.rb', __FILE__
|
67
|
+
load File.expand_path '../phony/countries/uruguay.rb', __FILE__
|
68
|
+
load File.expand_path '../phony/countries/zimbabwe.rb', __FILE__
|
64
69
|
|
65
70
|
# All other countries.
|
66
71
|
#
|
67
|
-
|
72
|
+
load File.expand_path '../phony/countries.rb', __FILE__
|
68
73
|
|
69
74
|
# Phony is the main module and is generally used to process
|
70
75
|
# E164 phone numbers directly.
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
describe 'Phony::Config' do
|
4
|
+
describe 'load' do
|
5
|
+
before do
|
6
|
+
# NOTE We redefine Phony as if it was not loaded for this set of tests.
|
7
|
+
Object.__send__(:remove_const, :Phony) if Object.constants.include?(:Phony)
|
8
|
+
|
9
|
+
load 'phony/config.rb'
|
10
|
+
end
|
11
|
+
after(:all) do
|
12
|
+
# After running this suite, we load all of Phony for the following tests.
|
13
|
+
load 'phony/config.rb'
|
14
|
+
|
15
|
+
Phony::Config.load
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'does not fail when loading all' do
|
19
|
+
Phony::Config.load
|
20
|
+
|
21
|
+
expect(Phony.split('15551115511')).to eq ['1', '555', '111', '5511']
|
22
|
+
end
|
23
|
+
it 'raises when a CC is used that has not been loaded.' do
|
24
|
+
Phony::Config.load('41')
|
25
|
+
|
26
|
+
expect { Phony.split('15551115511') }.to raise_error(Phony::SplittingError)
|
27
|
+
end
|
28
|
+
it 'raises when a CC is used that has not been loaded.' do
|
29
|
+
Phony::Config.load(only: ['41'])
|
30
|
+
|
31
|
+
expect { Phony.split('15551115511') }.to raise_error(Phony::SplittingError)
|
32
|
+
end
|
33
|
+
it 'raises when a CC is used that has not been loaded.' do
|
34
|
+
Phony::Config.load(except: ['1'])
|
35
|
+
|
36
|
+
expect { Phony.split('15551115511') }.to raise_error(Phony::SplittingError)
|
37
|
+
end
|
38
|
+
it 'does not raise when a CC is used that has been loaded.' do
|
39
|
+
Phony::Config.load(except: ['41'])
|
40
|
+
|
41
|
+
expect(Phony.split('15551115511')).to eq ['1', '555', '111', '5511']
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -25,11 +25,11 @@ describe 'plausibility' do
|
|
25
25
|
incorrect = [shortest.sub(/\d\s*\z/, '')] # , longest + '0']
|
26
26
|
|
27
27
|
correct.each do |value|
|
28
|
-
Phony.plausible?(value).
|
28
|
+
expect(Phony.plausible?(value)).to be_truthy,
|
29
29
|
"It should validate #{value}, but does not."
|
30
30
|
end
|
31
31
|
incorrect.each do |value|
|
32
|
-
Phony.plausible?(value).
|
32
|
+
expect(Phony.plausible?(value)).to be_falsey,
|
33
33
|
"It should not validate #{value}, but does."
|
34
34
|
end
|
35
35
|
end
|
@@ -38,7 +38,7 @@ describe 'plausibility' do
|
|
38
38
|
invalid = [*sample]
|
39
39
|
|
40
40
|
invalid.each do |value|
|
41
|
-
Phony.plausible?(value).
|
41
|
+
expect(Phony.plausible?(value)).to be_falsey,
|
42
42
|
"It should not validate #{value}, but does."
|
43
43
|
end
|
44
44
|
end
|
@@ -46,10 +46,155 @@ describe 'plausibility' do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
context 'specific countries' do
|
49
|
-
it_is_correct_for 'Austria', :samples => '+43 720 116987' # VoIP
|
49
|
+
it_is_correct_for 'Austria', :samples => ['+43 720 116987', # VoIP
|
50
|
+
'+43 463 12345'] # Klagenfurt
|
50
51
|
it_is_correct_for 'Bosnia and Herzegovina', :samples => ['+387 66 666 666',
|
51
52
|
'+387 37 123 456',
|
52
53
|
'+387 33 222 111']
|
54
|
+
it 'is correct for Brasil' do
|
55
|
+
Phony.plausible?('+55 67 998280912').should be_truthy
|
56
|
+
Phony.plausible?('+55 67 98280912').should be_falsey
|
57
|
+
Phony.plausible?('+55 11 12345678').should be_falsey
|
58
|
+
Phony.plausible?('+55 11 123456789').should be_falsey
|
59
|
+
Phony.plausible?('+55 11 023456789').should be_falsey
|
60
|
+
Phony.plausible?('+55 11 22345678').should be_truthy
|
61
|
+
end
|
62
|
+
it 'is correct for Bulgaria' do
|
63
|
+
Phony.plausible?('+359 2 1234567').should be_truthy
|
64
|
+
Phony.plausible?('+359 30 12345').should be_truthy
|
65
|
+
Phony.plausible?('+359 30 123456').should be_truthy
|
66
|
+
Phony.plausible?('+359 31 12345').should be_truthy
|
67
|
+
Phony.plausible?('+359 31 123456').should be_truthy
|
68
|
+
Phony.plausible?('+359 32 123456').should be_truthy
|
69
|
+
Phony.plausible?('+359 33 12345').should be_truthy
|
70
|
+
Phony.plausible?('+359 33 123456').should be_truthy
|
71
|
+
Phony.plausible?('+359 34 123456').should be_truthy
|
72
|
+
Phony.plausible?('+359 35 123456').should be_truthy
|
73
|
+
Phony.plausible?('+359 36 12345').should be_truthy
|
74
|
+
Phony.plausible?('+359 36 123456').should be_truthy
|
75
|
+
Phony.plausible?('+359 37 12345').should be_truthy
|
76
|
+
Phony.plausible?('+359 37 123456').should be_truthy
|
77
|
+
Phony.plausible?('+359 38 123456').should be_truthy
|
78
|
+
Phony.plausible?('+359 39 12345').should be_truthy
|
79
|
+
Phony.plausible?('+359 39 123456').should be_truthy
|
80
|
+
Phony.plausible?('+359 41 12345').should be_truthy
|
81
|
+
Phony.plausible?('+359 41 123456').should be_truthy
|
82
|
+
Phony.plausible?('+359 42 123456').should be_truthy
|
83
|
+
Phony.plausible?('+359 430 12345').should be_truthy
|
84
|
+
Phony.plausible?('+359 431 12345').should be_truthy
|
85
|
+
Phony.plausible?('+359 432 12345').should be_truthy
|
86
|
+
Phony.plausible?('+359 433 12345').should be_truthy
|
87
|
+
Phony.plausible?('+359 434 12345').should be_truthy
|
88
|
+
Phony.plausible?('+359 435 12345').should be_truthy
|
89
|
+
Phony.plausible?('+359 436 12345').should be_truthy
|
90
|
+
Phony.plausible?('+359 437 12345').should be_truthy
|
91
|
+
Phony.plausible?('+359 438 12345').should be_truthy
|
92
|
+
Phony.plausible?('+359 439 12345').should be_truthy
|
93
|
+
Phony.plausible?('+359 44 123456').should be_truthy
|
94
|
+
Phony.plausible?('+359 45 12345').should be_truthy
|
95
|
+
Phony.plausible?('+359 45 123456').should be_truthy
|
96
|
+
Phony.plausible?('+359 46 123456').should be_truthy
|
97
|
+
Phony.plausible?('+359 47 12345').should be_truthy
|
98
|
+
Phony.plausible?('+359 47 123456').should be_truthy
|
99
|
+
Phony.plausible?('+359 47 12345').should be_truthy
|
100
|
+
Phony.plausible?('+359 47 123456').should be_truthy
|
101
|
+
Phony.plausible?('+359 51 12345').should be_truthy
|
102
|
+
Phony.plausible?('+359 51 123456').should be_truthy
|
103
|
+
Phony.plausible?('+359 52 123456').should be_truthy
|
104
|
+
Phony.plausible?('+359 53 12345').should be_truthy
|
105
|
+
Phony.plausible?('+359 53 123456').should be_truthy
|
106
|
+
Phony.plausible?('+359 54 123456').should be_truthy
|
107
|
+
Phony.plausible?('+359 55 12345').should be_truthy
|
108
|
+
Phony.plausible?('+359 55 123456').should be_truthy
|
109
|
+
Phony.plausible?('+359 56 123456').should be_truthy
|
110
|
+
Phony.plausible?('+359 57 12345').should be_truthy
|
111
|
+
Phony.plausible?('+359 57 123456').should be_truthy
|
112
|
+
Phony.plausible?('+359 58 123456').should be_truthy
|
113
|
+
Phony.plausible?('+359 59 12345').should be_truthy
|
114
|
+
Phony.plausible?('+359 59 123456').should be_truthy
|
115
|
+
Phony.plausible?('+359 60 12345').should be_truthy
|
116
|
+
Phony.plausible?('+359 60 123456').should be_truthy
|
117
|
+
Phony.plausible?('+359 61 12345').should be_truthy
|
118
|
+
Phony.plausible?('+359 61 123456').should be_truthy
|
119
|
+
Phony.plausible?('+359 62 123456').should be_truthy
|
120
|
+
Phony.plausible?('+359 63 12345').should be_truthy
|
121
|
+
Phony.plausible?('+359 63 123456').should be_truthy
|
122
|
+
Phony.plausible?('+359 64 123456').should be_truthy
|
123
|
+
Phony.plausible?('+359 65 12345').should be_truthy
|
124
|
+
Phony.plausible?('+359 65 123456').should be_truthy
|
125
|
+
Phony.plausible?('+359 66 12345').should be_truthy
|
126
|
+
Phony.plausible?('+359 66 123456').should be_truthy
|
127
|
+
Phony.plausible?('+359 68 123456').should be_truthy
|
128
|
+
Phony.plausible?('+359 69 12345').should be_truthy
|
129
|
+
Phony.plausible?('+359 69 123456').should be_truthy
|
130
|
+
Phony.plausible?('+359 700 12345').should be_truthy
|
131
|
+
Phony.plausible?('+359 701 1234').should be_truthy
|
132
|
+
Phony.plausible?('+359 701 12345').should be_truthy
|
133
|
+
Phony.plausible?('+359 71 12345').should be_truthy
|
134
|
+
Phony.plausible?('+359 71 123456').should be_truthy
|
135
|
+
Phony.plausible?('+359 72 12345').should be_truthy
|
136
|
+
Phony.plausible?('+359 72 123456').should be_truthy
|
137
|
+
Phony.plausible?('+359 73 123456').should be_truthy
|
138
|
+
Phony.plausible?('+359 74 12345').should be_truthy
|
139
|
+
Phony.plausible?('+359 74 123456').should be_truthy
|
140
|
+
Phony.plausible?('+359 75 12345').should be_truthy
|
141
|
+
Phony.plausible?('+359 75 123456').should be_truthy
|
142
|
+
Phony.plausible?('+359 76 123456').should be_truthy
|
143
|
+
Phony.plausible?('+359 77 12345').should be_truthy
|
144
|
+
Phony.plausible?('+359 77 123456').should be_truthy
|
145
|
+
Phony.plausible?('+359 78 123456').should be_truthy
|
146
|
+
Phony.plausible?('+359 79 123456').should be_truthy
|
147
|
+
Phony.plausible?('+359 800 12345').should be_truthy
|
148
|
+
Phony.plausible?('+359 81 12345').should be_truthy
|
149
|
+
Phony.plausible?('+359 81 123456').should be_truthy
|
150
|
+
Phony.plausible?('+359 82 123456').should be_truthy
|
151
|
+
Phony.plausible?('+359 82 123456').should be_truthy
|
152
|
+
Phony.plausible?('+359 84 123456').should be_truthy
|
153
|
+
Phony.plausible?('+359 86 123456').should be_truthy
|
154
|
+
Phony.plausible?('+359 87 1234567').should be_truthy
|
155
|
+
Phony.plausible?('+359 88 1234567').should be_truthy
|
156
|
+
Phony.plausible?('+359 89 1234567').should be_truthy
|
157
|
+
Phony.plausible?('+359 90 123456').should be_truthy
|
158
|
+
Phony.plausible?('+359 91 12345').should be_truthy
|
159
|
+
Phony.plausible?('+359 91 123456').should be_truthy
|
160
|
+
Phony.plausible?('+359 92 123456').should be_truthy
|
161
|
+
Phony.plausible?('+359 93 12345').should be_truthy
|
162
|
+
Phony.plausible?('+359 93 123456').should be_truthy
|
163
|
+
Phony.plausible?('+359 94 123456').should be_truthy
|
164
|
+
Phony.plausible?('+359 95 12345').should be_truthy
|
165
|
+
Phony.plausible?('+359 95 123456').should be_truthy
|
166
|
+
Phony.plausible?('+359 96 123456').should be_truthy
|
167
|
+
Phony.plausible?('+359 97 12345').should be_truthy
|
168
|
+
Phony.plausible?('+359 97 123456').should be_truthy
|
169
|
+
Phony.plausible?('+359 980 123456').should be_truthy
|
170
|
+
Phony.plausible?('+359 981 123456').should be_truthy
|
171
|
+
Phony.plausible?('+359 982 123456').should be_truthy
|
172
|
+
Phony.plausible?('+359 983 123456').should be_truthy
|
173
|
+
Phony.plausible?('+359 984 123456').should be_truthy
|
174
|
+
Phony.plausible?('+359 985 123456').should be_truthy
|
175
|
+
Phony.plausible?('+359 986 123456').should be_truthy
|
176
|
+
Phony.plausible?('+359 987 123456').should be_truthy
|
177
|
+
Phony.plausible?('+359 988 123456').should be_truthy
|
178
|
+
Phony.plausible?('+359 989 123456').should be_truthy
|
179
|
+
Phony.plausible?('+359 990 123456').should be_truthy
|
180
|
+
Phony.plausible?('+359 991 123456').should be_truthy
|
181
|
+
Phony.plausible?('+359 992 123456').should be_truthy
|
182
|
+
Phony.plausible?('+359 993 123456').should be_truthy
|
183
|
+
Phony.plausible?('+359 994 123456').should be_truthy
|
184
|
+
Phony.plausible?('+359 995 123456').should be_truthy
|
185
|
+
Phony.plausible?('+359 996 123456').should be_truthy
|
186
|
+
Phony.plausible?('+359 997 123456').should be_truthy
|
187
|
+
Phony.plausible?('+359 998 123456').should be_truthy
|
188
|
+
Phony.plausible?('+359 999 123456').should be_truthy
|
189
|
+
end
|
190
|
+
it_is_correct_for 'Colombia', :samples => ['+57 601 411 1899',
|
191
|
+
'+57 602 111 2222',
|
192
|
+
'+57 603 111 2222',
|
193
|
+
'+57 604 111 2222',
|
194
|
+
'+57 605 111 2222',
|
195
|
+
'+57 606 111 2222',
|
196
|
+
'+57 607 111 2222',
|
197
|
+
'+57 608 111 2222']
|
53
198
|
it_is_correct_for 'Congo', :samples => '+242 1234 56789'
|
54
199
|
it_is_correct_for 'Cook Islands', :samples => '+682 71928'
|
55
200
|
it_is_correct_for 'Costa Rica', :samples => '+506 2 234 5678'
|
@@ -63,7 +208,7 @@ describe 'plausibility' do
|
|
63
208
|
Phony.plausible?('+385 60 12 345').should be_truthy # Premium rate
|
64
209
|
Phony.plausible?('+385 62 123 456').should be_truthy # Premium, personal and UAN
|
65
210
|
end
|
66
|
-
it_is_correct_for "Côte d'Ivoire", :samples => '+225
|
211
|
+
it_is_correct_for "Côte d'Ivoire", :samples => '+225 01 9358 8764'
|
67
212
|
it_is_correct_for 'Democratic Republic of Timor-Leste', :samples => ['+670 465 7886', '+670 7465 7886']
|
68
213
|
it_is_correct_for 'Democratic Republic of the Congo', :samples => '+243 80 864 9794'
|
69
214
|
it_is_correct_for 'Diego Garcia', :samples => '+246 123 7686'
|
@@ -120,10 +265,18 @@ describe 'plausibility' do
|
|
120
265
|
end
|
121
266
|
it_is_correct_for 'French Guiana (French Department of)', :samples => '+594 594 123 456'
|
122
267
|
it_is_correct_for "French Polynesia (Territoire français d'outre-mer)", :samples => '+689 87 27 84 00'
|
123
|
-
|
268
|
+
it 'is correct for Gabon' do
|
269
|
+
Phony.plausible?('+241 1 627 739').should be_truthy
|
270
|
+
Phony.plausible?('+241 12 34 56 78').should be_truthy
|
271
|
+
end
|
272
|
+
# it_is_correct_for 'Gabonese Republic', :samples => [
|
273
|
+
# '+241 1 627 739',
|
274
|
+
# '+241 12 34 56 78',
|
275
|
+
# ]
|
124
276
|
it_is_correct_for 'Gambia', :samples => '+220 989 5148'
|
125
277
|
it_is_correct_for 'Germany', :samples => [
|
126
|
-
'+49
|
278
|
+
'+49 69 155 1',
|
279
|
+
'+49 1577 536 8701'
|
127
280
|
]
|
128
281
|
it_is_correct_for 'Georgia', :samples => ['+995 220 123 45',
|
129
282
|
'+995 32 123 4567',
|
@@ -148,7 +301,7 @@ describe 'plausibility' do
|
|
148
301
|
'+964 71 1234 5678']
|
149
302
|
|
150
303
|
|
151
|
-
it_is_correct_for 'Kiribati (Republic of)', :samples => '+686
|
304
|
+
it_is_correct_for 'Kiribati (Republic of)', :samples => '+686 34814527'
|
152
305
|
it_is_correct_for "Democratic People's Republic of Korea", :samples => ['+850 2 123 45',
|
153
306
|
'+850 2 123 456 789',
|
154
307
|
'+850 2 381 2356',
|
@@ -187,10 +340,19 @@ describe 'plausibility' do
|
|
187
340
|
it_is_correct_for 'Macedonia', :samples => ['+389 2 123 4567',
|
188
341
|
'+389 7 124 3456',
|
189
342
|
'+389 7 234 5678']
|
190
|
-
it_is_correct_for 'Madagascar', :samples => ['+261 20
|
191
|
-
'+261
|
192
|
-
'+261
|
193
|
-
'+261
|
343
|
+
it_is_correct_for 'Madagascar', :samples => ['+261 20 23 456 78',
|
344
|
+
'+261 32 34 546 78',
|
345
|
+
'+261 33 34 546 78',
|
346
|
+
'+261 34 34 546 78',
|
347
|
+
'+261 38 34 546 78']
|
348
|
+
it 'is incorrect for Madagascar' do
|
349
|
+
Phony.plausible?('+261 20 012 345 678').should be_falsey
|
350
|
+
Phony.plausible?('+261 20 12 434 569').should be_falsey
|
351
|
+
Phony.plausible?('+261 51 23 4567 8').should be_falsey
|
352
|
+
Phony.plausible?('+261 34 345 46789').should be_falsey
|
353
|
+
Phony.plausible?('+261 34 345 467').should be_falsey
|
354
|
+
end
|
355
|
+
|
194
356
|
it_is_correct_for 'Malawi', :samples => ['+265 1725 123',
|
195
357
|
'+265 213 456 789',
|
196
358
|
'+265 9123 456',
|
@@ -201,7 +363,8 @@ describe 'plausibility' do
|
|
201
363
|
it_is_correct_for 'Marshall Islands (Republic of the)', :samples => '+692 372 7183'
|
202
364
|
it_is_correct_for 'Martinique (French Department of)', :samples => '+596 596 123 456'
|
203
365
|
it_is_correct_for 'Mauritania', :samples => '+222 1234 5678'
|
204
|
-
it_is_correct_for 'Mauritius', :samples => '+230
|
366
|
+
it_is_correct_for 'Mauritius', :samples => ['+230 5 695 2277',
|
367
|
+
'+230 260 0070']
|
205
368
|
it_is_correct_for 'Micronesia (Federated States of)', :samples => '+691 766 7914'
|
206
369
|
it_is_correct_for 'Moldova', :samples => ['+373 800 123 45',
|
207
370
|
'+373 22 123 345',
|
@@ -225,14 +388,49 @@ describe 'plausibility' do
|
|
225
388
|
end
|
226
389
|
it_is_correct_for 'Nicaragua', :samples => '+505 12 345 678'
|
227
390
|
it_is_correct_for 'Niger', :samples => '+227 1234 5678'
|
391
|
+
it_is_correct_for 'Nigeria', :samples => ['+234 807 059 1111',
|
392
|
+
'+234 811 234 5678',
|
393
|
+
'+234 64 830 00',
|
394
|
+
'+234 1 280 444',
|
395
|
+
'+234 85 123 456']
|
228
396
|
it_is_correct_for 'Niue', :samples => '+683 3791'
|
229
397
|
it_is_correct_for 'Oman', :samples => ['+968 24 423 123',
|
230
398
|
'+968 25 423 123']
|
231
399
|
it_is_correct_for 'Palau (Republic of)', :samples => '+680 483 7871'
|
400
|
+
|
401
|
+
it_is_correct_for 'Papua New Guinea', :samples => ['+675 180 1234',
|
402
|
+
'+675 170 12',
|
403
|
+
'+675 189 1',
|
404
|
+
'+675 184 1234 5678',
|
405
|
+
'+675 185 1234',
|
406
|
+
'+675 275 1234',
|
407
|
+
'+675 278 12',
|
408
|
+
'+675 115 1234 5678',
|
409
|
+
'+675 28 123 45',
|
410
|
+
'+675 16 123 12',
|
411
|
+
'+675 711 23 456',
|
412
|
+
'+675 731 23 456',
|
413
|
+
'+675 741 23 456',
|
414
|
+
'+675 770 12 345',
|
415
|
+
'+675 771 12 345',
|
416
|
+
'+675 772 12 345',
|
417
|
+
'+675 773 01 234',
|
418
|
+
'+675 774 12 345',
|
419
|
+
'+675 775 12 345',
|
420
|
+
'+675 80 123 456',
|
421
|
+
'+675 90 123 456',
|
422
|
+
'+675 3 123 456']
|
423
|
+
|
232
424
|
it_is_correct_for 'Panama (Republic of)', :samples => ['+507 800 1234',
|
233
425
|
'+507 6 123 4567',
|
234
426
|
'+507 2 123 456']
|
235
427
|
it_is_correct_for 'Reunion / Mayotte (new)', :samples => '+262 295 276 964'
|
428
|
+
it_is_correct_for 'Rwanda', :samples => ['+250 72 1234567',
|
429
|
+
'+250 73 1234567',
|
430
|
+
'+250 78 1234567',
|
431
|
+
'+250 79 1234567',
|
432
|
+
'+250 25 1234567',
|
433
|
+
'+250 06 123456']
|
236
434
|
it_is_correct_for 'Saint Helena', :samples => '+290 5134'
|
237
435
|
it_is_correct_for 'Saint Pierre and Miquelon (Collectivité territoriale de la République française)', :samples => '+508 474 714'
|
238
436
|
it_is_correct_for 'Salvador (El)', :samples => [
|
@@ -261,8 +459,10 @@ describe 'plausibility' do
|
|
261
459
|
['+381 11 123 456', '+381 11 123 4567'],
|
262
460
|
'+381 72 123 456',
|
263
461
|
'+381 60 123',
|
264
|
-
'+381 60 123 4567',
|
462
|
+
['+381 60 123 4567', '+381 69 123 456'],
|
265
463
|
'+381 42 123 456',
|
464
|
+
'+381 677 123 456',
|
465
|
+
'+381 678 123 456',
|
266
466
|
'+381 9 123 4567',
|
267
467
|
'+381 60 123',
|
268
468
|
'+381 60 123 456 7890',
|
@@ -333,7 +533,10 @@ describe 'plausibility' do
|
|
333
533
|
it_is_correct_for 'Lybia', :samples => ['+218 205 123 45',
|
334
534
|
'+218 22 123 456',
|
335
535
|
'+218 21 1234 456',
|
336
|
-
'+218 91 1234 456'
|
536
|
+
'+218 91 1234 456',
|
537
|
+
'+218 92 1234 456',
|
538
|
+
'+218 94 1234 456',
|
539
|
+
'+218 95 1234 456']
|
337
540
|
it_is_correct_for 'Mongolia', :samples => ['+976 11 123 45',
|
338
541
|
['+976 121 12 34', '+976 121 12 345'],
|
339
542
|
'+976 70 123 456',
|
@@ -367,6 +570,7 @@ describe 'plausibility' do
|
|
367
570
|
]
|
368
571
|
it_is_correct_for 'United Arab Emirates', :samples => ['+971 800 12',
|
369
572
|
'+971 800 12 345 6789',
|
573
|
+
'+971 800 12 345 67',
|
370
574
|
'+971 2 123 4567',
|
371
575
|
'+971 50 641 2345',
|
372
576
|
'+971 600 641 234',
|
@@ -384,15 +588,21 @@ describe 'plausibility' do
|
|
384
588
|
'+598 93 123 456',
|
385
589
|
'+598 908 123 45',
|
386
590
|
'+598 805 123 45']
|
591
|
+
it_is_correct_for 'Vietnam', :samples => ['+84 24 41234567',
|
592
|
+
'+84 28 41234567',
|
593
|
+
'+84 23 61234567']
|
387
594
|
it_is_correct_for 'Yemen', :samples => [['+967 1 234 567', '+967 1 234 5678'],
|
388
595
|
'+967 7 234 567',
|
389
596
|
'+967 77 123 4567',
|
390
597
|
'+967 58 1234']
|
391
598
|
it 'is correct for Zambia' do
|
392
599
|
Phony.plausible?('+260 211 123456').should be_truthy # Fixed
|
393
|
-
Phony.plausible?('+260
|
394
|
-
Phony.plausible?('+260
|
395
|
-
Phony.plausible?('+260
|
600
|
+
Phony.plausible?('+260 96 512 4567').should be_truthy # MTN Mobile
|
601
|
+
Phony.plausible?('+260 97 712 3456').should be_truthy # Airtel Mobile
|
602
|
+
Phony.plausible?('+260 95 512 4567').should be_truthy # Zamtel Mobile
|
603
|
+
Phony.plausible?('+260 96 512 456').should be_falsy # MTN Mobile (Too short)
|
604
|
+
Phony.plausible?('+260 97 812 345').should be_falsy # Airtel Mobile (Too short)
|
605
|
+
Phony.plausible?('+260 95 512 345').should be_falsy # Zamtel Mobile (Too short)
|
396
606
|
Phony.plausible?('+260 800 123 456').should be_truthy # Toll free
|
397
607
|
end
|
398
608
|
it_is_correct_for 'Zimbabwe', :samples => [['+263 2582 123 456', '+263 2582 123'],
|
@@ -407,10 +617,67 @@ describe 'plausibility' do
|
|
407
617
|
Phony.plausible?('+62 22 0000 0000').should be_truthy
|
408
618
|
Phony.plausible?('+62 22 000 000 000').should be_truthy
|
409
619
|
end
|
620
|
+
|
621
|
+
it 'is correct for Italy' do
|
622
|
+
Phony.plausible?('+39 0574 123').should be_falsy
|
623
|
+
Phony.plausible?('+39 0574 1234').should be_truthy
|
624
|
+
Phony.plausible?('+39 0574 12345').should be_falsy
|
625
|
+
|
626
|
+
Phony.plausible?('+39 085 541').should be_falsy
|
627
|
+
Phony.plausible?('+39 085 5410').should be_truthy
|
628
|
+
Phony.plausible?('+39 085 54105').should be_truthy
|
629
|
+
|
630
|
+
Phony.plausible?('+39 06 4991').should be_falsy
|
631
|
+
Phony.plausible?('+39 06 49911').should be_truthy
|
632
|
+
Phony.plausible?('+39 06 499112').should be_truthy
|
633
|
+
|
634
|
+
Phony.plausible?('+39 800 081631').should be_truthy
|
635
|
+
Phony.plausible?('+39 800 0816311').should be_falsy
|
636
|
+
|
637
|
+
Phony.plausible?('+39 803 08163').should be_falsy
|
638
|
+
Phony.plausible?('+39 803 081').should be_truthy
|
639
|
+
end
|
410
640
|
|
411
641
|
it 'is correct for Russia' do
|
412
642
|
Phony.plausible?('+7 3522 000 000').should be_truthy
|
413
643
|
end
|
644
|
+
|
645
|
+
it 'is correct for Peru' do
|
646
|
+
Phony.plausible?('+51 1 123 1234').should be_truthy # Lima
|
647
|
+
Phony.plausible?('+51 9 1234 1234').should be_truthy # mobile
|
648
|
+
Phony.plausible?('+51 84 123 123').should be_truthy # Cuzco, best effort
|
649
|
+
end
|
650
|
+
|
651
|
+
it 'is correct for Kosovo' do
|
652
|
+
Phony.plausible?('+383 29 000 000').should be_truthy # Landline
|
653
|
+
Phony.plausible?('+383 44 000 000').should be_truthy # Mobile
|
654
|
+
end
|
655
|
+
|
656
|
+
it 'is correct for Bulgaria' do
|
657
|
+
Phony.plausible?('+359 2 123 123').should be_truthy # Landline Sofia
|
658
|
+
Phony.plausible?('+359 2 123 1234').should be_truthy # Landline Sofia
|
659
|
+
Phony.plausible?('+359 30 123 12').should be_truthy # Landline
|
660
|
+
Phony.plausible?('+359 30 123 123').should be_truthy # Landline
|
661
|
+
Phony.plausible?('+359 89 123 1234').should be_truthy # Mobile
|
662
|
+
end
|
663
|
+
|
664
|
+
it 'is correct for Malaysia' do
|
665
|
+
Phony.plausible?('+60 5 123 1234').should be_truthy # Non Selangor Landline
|
666
|
+
Phony.plausible?('+60 3 1234 1234').should be_truthy # Selangor Landline
|
667
|
+
Phony.plausible?('+60 88 123 123').should be_truthy # Landline Sabah – Kota Kinabalu and Kudat
|
668
|
+
end
|
669
|
+
|
670
|
+
it 'is correct for Japan' do
|
671
|
+
Phony.plausible?('+81 90 1234 1234').should be_truthy
|
672
|
+
Phony.plausible?('+81 120 123 123').should be_truthy
|
673
|
+
Phony.plausible?('+81 800 123 1234').should be_truthy
|
674
|
+
end
|
675
|
+
|
676
|
+
it 'is correct for Philippine' do
|
677
|
+
Phony.plausible?('+63 2 89889999').should be_truthy
|
678
|
+
Phony.plausible?('+63 976 1234567').should be_truthy # mobile phone with area code 9
|
679
|
+
Phony.plausible?('+63 876 1234567').should be_truthy # mobile phone with area code 8
|
680
|
+
end
|
414
681
|
end
|
415
682
|
end
|
416
683
|
end
|