phony 1.9.0 → 2.19.14
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.
- checksums.yaml +7 -0
- data/README.textile +64 -112
- data/lib/phony/config.rb +91 -0
- data/lib/phony/countries/argentina.rb +355 -0
- data/lib/phony/countries/austria.rb +56 -22
- data/lib/phony/countries/bangladesh.rb +57 -0
- data/lib/phony/countries/belarus.rb +133 -0
- data/lib/phony/countries/brazil.rb +101 -95
- data/lib/phony/countries/cambodia.rb +131 -0
- data/lib/phony/countries/china.rb +13 -6
- data/lib/phony/countries/croatia.rb +23 -0
- data/lib/phony/countries/georgia.rb +94 -0
- data/lib/phony/countries/germany.rb +66 -42
- data/lib/phony/countries/guinea.rb +46 -0
- data/lib/phony/countries/india.rb +50 -0
- data/lib/phony/countries/indonesia.rb +55 -0
- data/lib/phony/countries/ireland.rb +35 -28
- data/lib/phony/countries/italy.rb +272 -166
- data/lib/phony/countries/japan.rb +468 -0
- data/lib/phony/countries/kyrgyzstan.rb +120 -0
- data/lib/phony/countries/latvia.rb +43 -0
- data/lib/phony/countries/libya.rb +116 -0
- data/lib/phony/countries/malaysia.rb +31 -7
- data/lib/phony/countries/moldova.rb +53 -0
- data/lib/phony/countries/montenegro.rb +30 -0
- data/lib/phony/countries/myanmar.rb +55 -0
- data/lib/phony/countries/namibia.rb +37 -0
- data/lib/phony/countries/nepal.rb +73 -0
- data/lib/phony/countries/netherlands.rb +17 -5
- data/lib/phony/countries/pakistan.rb +121 -0
- data/lib/phony/countries/paraguay.rb +147 -0
- data/lib/phony/countries/{russia_kazakhstan_abhasia_south_osetia.rb → russia_kazakhstan_abkhasia_south_ossetia.rb} +35 -24
- data/lib/phony/countries/saudi_arabia.rb +40 -0
- data/lib/phony/countries/serbia.rb +47 -0
- data/lib/phony/countries/somalia.rb +26 -0
- data/lib/phony/countries/south_korea.rb +19 -10
- data/lib/phony/countries/sweden.rb +58 -38
- data/lib/phony/countries/taiwan.rb +28 -0
- data/lib/phony/countries/tajikistan.rb +79 -0
- data/lib/phony/countries/turkmenistan.rb +76 -0
- data/lib/phony/countries/ukraine.rb +630 -0
- data/lib/phony/countries/united_kingdom.rb +639 -44
- data/lib/phony/countries/uruguay.rb +53 -0
- data/lib/phony/countries/vietnam.rb +133 -0
- data/lib/phony/countries/zimbabwe.rb +39 -0
- data/lib/phony/countries.rb +901 -301
- data/lib/phony/country.rb +177 -20
- data/lib/phony/country_codes.rb +119 -101
- data/lib/phony/dsl.rb +113 -68
- data/lib/phony/local_splitters/fixed.rb +25 -1
- data/lib/phony/local_splitters/regex.rb +16 -2
- data/lib/phony/national_code.rb +7 -7
- data/lib/phony/national_splitters/default.rb +35 -3
- data/lib/phony/national_splitters/dsl.rb +12 -7
- data/lib/phony/national_splitters/fixed.rb +7 -1
- data/lib/phony/national_splitters/none.rb +7 -3
- data/lib/phony/national_splitters/regex.rb +6 -0
- data/lib/phony/national_splitters/variable.rb +13 -9
- data/lib/phony/trunk_code.rb +57 -0
- data/lib/phony/vanity.rb +3 -3
- data/lib/phony.rb +239 -55
- data/spec/functional/config_spec.rb +44 -0
- data/spec/functional/plausibility_spec.rb +656 -0
- data/spec/lib/phony/countries_spec.rb +1207 -119
- data/spec/lib/phony/country_codes_spec.rb +99 -81
- data/spec/lib/phony/country_spec.rb +54 -14
- data/spec/lib/phony/dsl_spec.rb +2 -2
- data/spec/lib/phony/local_splitters/fixed_spec.rb +4 -4
- data/spec/lib/phony/local_splitters/regex_spec.rb +50 -2
- data/spec/lib/phony/national_code_spec.rb +34 -34
- data/spec/lib/phony/national_splitters/default_spec.rb +34 -0
- data/spec/lib/phony/national_splitters/fixed_spec.rb +12 -6
- data/spec/lib/phony/national_splitters/none_spec.rb +13 -3
- data/spec/lib/phony/national_splitters/regex_spec.rb +1 -1
- data/spec/lib/phony/national_splitters/variable_spec.rb +11 -5
- data/spec/lib/phony/trunk_code_spec.rb +85 -0
- data/spec/lib/phony/vanity_spec.rb +15 -19
- data/spec/lib/phony_spec.rb +59 -277
- metadata +67 -34
- data/lib/phony/validator.rb +0 -26
- data/lib/phony/validators.rb +0 -88
- data/spec/lib/phony/validations_spec.rb +0 -109
@@ -2,185 +2,203 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Phony::CountryCodes do
|
4
4
|
|
5
|
-
|
6
|
-
@countries = Phony::CountryCodes.instance
|
7
|
-
end
|
5
|
+
let(:countries) { Phony::CountryCodes.instance }
|
8
6
|
|
9
|
-
describe '
|
10
|
-
it '
|
11
|
-
|
7
|
+
describe '#[]' do
|
8
|
+
it 'returns a country' do
|
9
|
+
countries['41'].class.should eql Phony::Country
|
12
10
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@countries.international_absolute_format = old_format
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#country_for' do
|
14
|
+
it 'returns a country' do
|
15
|
+
countries.send(:country_for, '41').class.should eql Phony::Country
|
20
16
|
end
|
21
17
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
|
19
|
+
describe '#countrify' do
|
20
|
+
it 'returns a country' do
|
21
|
+
countries.send(:countrify, '441231212', '41').should eql '41441231212'
|
25
22
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
end
|
24
|
+
describe '#countrify!' do
|
25
|
+
it 'in-place replaces the number' do
|
26
|
+
number = '441231212'
|
27
|
+
countries.send(:countrify!, number, '41').should eql number
|
31
28
|
|
32
|
-
|
29
|
+
number.should == '41441231212'
|
33
30
|
end
|
34
31
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
|
33
|
+
describe '#vanity?' do
|
34
|
+
it 'returns true if so' do
|
35
|
+
countries.vanity?('1800HELLOES').should eql true
|
38
36
|
end
|
39
|
-
it '
|
40
|
-
|
41
|
-
@countries.national_format = '%s%s'
|
42
|
-
|
43
|
-
@countries.formatted('11231231234', :format => :national).should == '123 123 1234'
|
44
|
-
|
45
|
-
@countries.national_format = old_format
|
37
|
+
it 'returns false if not' do
|
38
|
+
countries.vanity?('18001234567').should eql false
|
46
39
|
end
|
47
40
|
end
|
48
|
-
|
49
|
-
describe '
|
50
|
-
it '
|
51
|
-
|
41
|
+
|
42
|
+
describe 'normalize' do
|
43
|
+
it 'normalizes correctly' do
|
44
|
+
countries.normalize('0041-44-364-35-32').should eql '41443643532'
|
45
|
+
end
|
46
|
+
it 'normalizes correctly with CC option' do
|
47
|
+
countries.normalize('044-364-35-32', cc: '41').should eql '41443643532'
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'specific countries' do
|
51
|
+
it 'handles Congo correctly' do
|
52
|
+
countries.normalize('+242 0571 73992').should eql '242057173992'
|
53
|
+
countries.normalize('+242 2221 15932').should eql '242222115932'
|
54
|
+
end
|
52
55
|
end
|
53
56
|
end
|
54
|
-
|
57
|
+
|
55
58
|
describe 'formatted' do
|
56
59
|
it 'formats correctly' do
|
57
|
-
|
60
|
+
countries.formatted('41443643532', :format => :international, :spaces => :-).should eql '+41-44-364-35-32'
|
58
61
|
end
|
59
62
|
it 'formats correctly' do
|
60
|
-
|
63
|
+
countries.formatted('41443643532', :format => :international_relative, :spaces => :-).should eql '0041-44-364-35-32'
|
61
64
|
end
|
62
65
|
it 'formats correctly' do
|
63
|
-
|
66
|
+
countries.formatted('41443643532', :format => :national, :spaces => :-).should eql '044-364-35-32'
|
64
67
|
end
|
65
68
|
context 'specific' do
|
66
|
-
it 'formats
|
67
|
-
|
69
|
+
it 'formats Ireland correctly' do
|
70
|
+
countries.formatted("3533451234", :format => :national).should eql '0345 1234'
|
71
|
+
end
|
72
|
+
it 'formats Ireland correctly' do
|
73
|
+
countries.formatted("353411231234", :format => :national).should eql '041 123 1234'
|
74
|
+
end
|
75
|
+
it 'formats Spain correctly' do
|
76
|
+
countries.formatted("34123456789", :format => :national).should eql '123 456 789'
|
77
|
+
end
|
78
|
+
it 'formats Cambodia correctly' do
|
79
|
+
countries.formatted('85512239123', :format => :national).should eql '012 239 123'
|
68
80
|
end
|
69
|
-
it 'formats
|
70
|
-
|
81
|
+
it 'formats the US correctly' do
|
82
|
+
countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
|
83
|
+
end
|
84
|
+
it 'formats the US correctly' do
|
85
|
+
countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
|
71
86
|
end
|
72
87
|
end
|
73
88
|
context 'default' do
|
74
89
|
it "should format swiss numbers" do
|
75
|
-
|
90
|
+
countries.formatted('41443643532').should eql '+41 44 364 35 32'
|
76
91
|
end
|
77
92
|
it "should format swiss service numbers" do
|
78
|
-
|
93
|
+
countries.formatted('41800112233').should eql '+41 800 112 233'
|
79
94
|
end
|
80
95
|
it "should format austrian numbers" do
|
81
|
-
|
96
|
+
countries.formatted('43198110').should eql '+43 1 98110'
|
82
97
|
end
|
83
98
|
it "should format american numbers" do
|
84
|
-
|
99
|
+
countries.formatted('18705551122').should eql '+1 (870) 555-1122'
|
85
100
|
end
|
86
101
|
it "should format irish numbers" do
|
87
|
-
|
102
|
+
countries.formatted('35311234567').should eql '+353 1 123 4567'
|
88
103
|
end
|
89
104
|
end
|
90
105
|
describe "international" do
|
91
106
|
it "should format north american numbers" do
|
92
|
-
|
107
|
+
countries.formatted('18091231234', :format => :international).should eql '+1 (809) 123-1234'
|
93
108
|
end
|
94
109
|
it "should format austrian numbers" do
|
95
|
-
|
110
|
+
countries.formatted('43198110', :format => :international).should eql '+43 1 98110'
|
96
111
|
end
|
97
112
|
it "should format austrian numbers" do
|
98
|
-
|
113
|
+
countries.formatted('43198110', :format => :international_absolute).should eql '+43 1 98110'
|
99
114
|
end
|
100
115
|
it "should format french numbers" do
|
101
|
-
|
116
|
+
countries.formatted('33142278186', :format => :+).should eql '+33 1 42 27 81 86'
|
102
117
|
end
|
103
118
|
it "should format austrian numbers" do
|
104
|
-
|
119
|
+
countries.formatted('43198110', :format => :international_relative).should eql '0043 1 98110'
|
105
120
|
end
|
106
121
|
it 'should format liechtensteiner numbers' do
|
107
|
-
|
122
|
+
countries.formatted('4233841148', :format => :international_relative).should eql '00423 384 11 48'
|
108
123
|
end
|
109
124
|
it "should format irish numbers" do
|
110
|
-
|
125
|
+
countries.formatted('35311234567', :format => :international).should eql '+353 1 123 4567'
|
111
126
|
end
|
112
127
|
it "should format luxembourgian numbers" do
|
113
|
-
|
128
|
+
countries.formatted('352222809', :format => :international).should eql '+352 22 28 09'
|
114
129
|
end
|
115
130
|
it "should format luxembourgian 4-digit ndc numbers" do
|
116
|
-
|
131
|
+
countries.formatted('35226222809', :format => :international).should eql '+352 2622 28 09'
|
117
132
|
end
|
118
133
|
it "should format luxembourgian mobile numbers" do
|
119
|
-
|
134
|
+
countries.formatted('352621123456', :format => :international).should eql '+352 621 123 456'
|
120
135
|
end
|
121
136
|
it "should format luxembourgian city numbers" do
|
122
|
-
|
137
|
+
countries.formatted('3524123456', :format => :international).should eql '+352 41 23 45 6'
|
123
138
|
end
|
124
139
|
it "should format luxembourgian machine to machine numbers" do
|
125
|
-
|
140
|
+
countries.formatted('352602112345678', :format => :international).should eql '+352 6021 12 34 56 78'
|
126
141
|
end
|
127
142
|
it "should format luxembourgian numbers" do
|
128
|
-
|
143
|
+
countries.formatted('352370431', :format => :international).should eql '+352 37 04 31'
|
129
144
|
end
|
130
145
|
it "should format luxembourgian numbers" do
|
131
|
-
|
146
|
+
countries.formatted('35227855', :format => :international).should eql '+352 27 85 5'
|
147
|
+
end
|
148
|
+
it "should format nigerian lagosian numbers" do
|
149
|
+
countries.formatted('23414480000', :format => :international).should eql '+234 1 448 0000'
|
132
150
|
end
|
133
|
-
it "should format nigerian numbers" do
|
134
|
-
|
151
|
+
it "should format nigerian beninese numbers" do
|
152
|
+
countries.formatted('23452123456', :format => :international).should eql '+234 52 123 456'
|
135
153
|
end
|
136
154
|
it "should format nigerian mobile numbers" do
|
137
|
-
|
155
|
+
countries.formatted('2347061234567', :format => :international).should eql '+234 706 123 4567'
|
138
156
|
end
|
139
157
|
context 'with no spaces' do
|
140
158
|
it "should format north american numbers" do
|
141
|
-
Phony.formatted('18091231234', :format => :international, :spaces => '').should
|
159
|
+
Phony.formatted('18091231234', :format => :international, :spaces => '').should eql '+1(809)123-1234'
|
142
160
|
end
|
143
161
|
it "should format austrian numbers" do
|
144
|
-
Phony.formatted('43198110', :format => :international, :spaces => '').should
|
162
|
+
Phony.formatted('43198110', :format => :international, :spaces => '').should eql '+43198110'
|
145
163
|
end
|
146
164
|
it "should format austrian numbers" do
|
147
|
-
Phony.formatted('43198110', :format => :international_absolute, :spaces => '').should
|
165
|
+
Phony.formatted('43198110', :format => :international_absolute, :spaces => '').should eql '+43198110'
|
148
166
|
end
|
149
167
|
it "should format french numbers" do
|
150
|
-
Phony.formatted('33142278186', :format => :+, :spaces => '').should
|
168
|
+
Phony.formatted('33142278186', :format => :+, :spaces => '').should eql '+33142278186'
|
151
169
|
end
|
152
170
|
it "should format austrian numbers" do
|
153
|
-
Phony.formatted('43198110', :format => :international_relative, :spaces => '').should
|
171
|
+
Phony.formatted('43198110', :format => :international_relative, :spaces => '').should eql '0043198110'
|
154
172
|
end
|
155
173
|
it 'should format liechtensteiner numbers' do
|
156
|
-
Phony.formatted('4233841148', :format => :international_relative, :spaces => '').should
|
174
|
+
Phony.formatted('4233841148', :format => :international_relative, :spaces => '').should eql '004233841148'
|
157
175
|
end
|
158
176
|
end
|
159
177
|
context 'with special spaces' do
|
160
178
|
it "should format swiss numbers" do
|
161
|
-
Phony.formatted('41443643532', :format => :international).should
|
179
|
+
Phony.formatted('41443643532', :format => :international).should eql '+41 44 364 35 32'
|
162
180
|
end
|
163
181
|
it "should format north american numbers" do
|
164
|
-
Phony.formatted('18091231234', :format => :international, :spaces => :-).should
|
182
|
+
Phony.formatted('18091231234', :format => :international, :spaces => :-).should eql '+1-(809)-123-1234'
|
165
183
|
end
|
166
184
|
it "should format austrian numbers" do
|
167
|
-
Phony.formatted('43198110', :format => :international, :spaces => :-).should
|
185
|
+
Phony.formatted('43198110', :format => :international, :spaces => :-).should eql '+43-1-98110'
|
168
186
|
end
|
169
187
|
it "should format austrian numbers" do
|
170
|
-
Phony.formatted('43198110', :format => :international_absolute, :spaces => :-).should
|
188
|
+
Phony.formatted('43198110', :format => :international_absolute, :spaces => :-).should eql '+43-1-98110'
|
171
189
|
end
|
172
190
|
it "should format french numbers" do
|
173
|
-
Phony.formatted('33142278186', :format => :+, :spaces => :-).should
|
191
|
+
Phony.formatted('33142278186', :format => :+, :spaces => :-).should eql '+33-1-42-27-81-86'
|
174
192
|
end
|
175
193
|
it "should format austrian numbers" do
|
176
|
-
Phony.formatted('43198110', :format => :international_relative, :spaces => :-).should
|
194
|
+
Phony.formatted('43198110', :format => :international_relative, :spaces => :-).should eql '0043-1-98110'
|
177
195
|
end
|
178
196
|
it 'should format liechtensteiner numbers' do
|
179
|
-
Phony.formatted('4233841148', :format => :international_relative, :spaces => :-).should
|
197
|
+
Phony.formatted('4233841148', :format => :international_relative, :spaces => :-).should eql '00423-384-11-48'
|
180
198
|
end
|
181
199
|
|
182
200
|
end
|
183
201
|
end
|
184
202
|
end
|
185
|
-
|
186
|
-
end
|
203
|
+
|
204
|
+
end
|
@@ -2,44 +2,84 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Phony::Country do
|
4
4
|
|
5
|
+
describe 'general' do
|
6
|
+
let(:country) do
|
7
|
+
national_splitter = Phony::NationalSplitters::Variable.new 4, ['44']
|
8
|
+
local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
|
9
|
+
national_code = Phony::NationalCode.new national_splitter, local_splitter
|
10
|
+
|
11
|
+
Phony::Country.new national_code
|
12
|
+
end
|
13
|
+
describe '#clean' do
|
14
|
+
it 'cleans the number' do
|
15
|
+
country.clean('+41-44-123-12-12').should eql '41441231212'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
describe '#vanity_to_number' do
|
19
|
+
it 'turns the vanity number into a number' do
|
20
|
+
country.vanity_to_number('1-800-HELLO').should eql '1-800-43556'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
5
25
|
context 'regression' do
|
6
|
-
describe '
|
7
|
-
|
26
|
+
describe 'Iceland' do
|
27
|
+
let(:country) do
|
8
28
|
national_splitter = Phony::NationalSplitters::None.instance_for
|
9
29
|
local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 4]
|
10
30
|
|
11
31
|
national_code = Phony::NationalCode.new national_splitter, local_splitter
|
12
|
-
|
32
|
+
described_class.new national_code
|
33
|
+
end
|
34
|
+
it 'splits correctly' do
|
35
|
+
country.split('112').should == [nil, false, '112']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
describe 'San Marino' do
|
39
|
+
it 'normalizes correctly' do
|
40
|
+
Phony.normalize('+3780549903549').should == '3780549903549'
|
41
|
+
end
|
42
|
+
xit 'automatically adds the sole NC' do
|
43
|
+
Phony.normalize('+378903549').should == '3780549903549'
|
44
|
+
end
|
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'
|
13
53
|
end
|
14
54
|
it 'splits correctly' do
|
15
|
-
|
55
|
+
Phony.split('81312345634').should == %w(81 3 1234 5634)
|
16
56
|
end
|
17
57
|
end
|
18
58
|
end
|
19
59
|
|
20
|
-
context "without special cases" do
|
21
|
-
|
60
|
+
context "without special cases (with switzerland)" do
|
61
|
+
let(:country) do
|
22
62
|
national_splitter = Phony::NationalSplitters::Variable.new 4, ['44']
|
23
63
|
local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
|
24
64
|
national_code = Phony::NationalCode.new national_splitter, local_splitter
|
25
65
|
|
26
|
-
|
66
|
+
Phony::Country.new national_code
|
27
67
|
end
|
28
68
|
|
29
69
|
describe "split" do
|
30
70
|
it "should handle ZH" do
|
31
|
-
|
71
|
+
country.split('443643532').should == [nil, '44', '364', '35', '32']
|
32
72
|
end
|
33
73
|
end
|
34
74
|
describe 'normalize' do
|
35
75
|
it "should handle ZH" do
|
36
|
-
|
76
|
+
country.normalize('0443643532').should == '443643532'
|
37
77
|
end
|
38
78
|
end
|
39
79
|
end
|
40
80
|
|
41
81
|
context "without special cases" do
|
42
|
-
|
82
|
+
let(:country) do
|
43
83
|
special_national_splitter = Phony::NationalSplitters::Variable.new nil, ['800']
|
44
84
|
special_local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 3]
|
45
85
|
special_code = Phony::NationalCode.new special_national_splitter, special_local_splitter
|
@@ -48,17 +88,17 @@ describe Phony::Country do
|
|
48
88
|
local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
|
49
89
|
national_code = Phony::NationalCode.new national_splitter, local_splitter
|
50
90
|
|
51
|
-
|
91
|
+
Phony::Country.new special_code, national_code
|
52
92
|
end
|
53
93
|
|
54
94
|
describe "split" do
|
55
95
|
it "should handle ZH" do
|
56
|
-
|
96
|
+
country.split('443643532').should == [nil, '44', '364', '35', '32']
|
57
97
|
end
|
58
98
|
it "should handle 800" do
|
59
|
-
|
99
|
+
country.split('800333666').should == [nil, '800', '333', '666']
|
60
100
|
end
|
61
101
|
end
|
62
102
|
end
|
63
103
|
|
64
|
-
end
|
104
|
+
end
|
data/spec/lib/phony/dsl_spec.rb
CHANGED
@@ -16,8 +16,8 @@ describe Phony::DSL do
|
|
16
16
|
it 'checks for ( in regex' do
|
17
17
|
expect { dsl.match(/123/) }.to raise_error("Regexp /123/ needs a group in it that defines which digits belong to the NDC.")
|
18
18
|
end
|
19
|
-
it '
|
20
|
-
dsl.match(/(123)/).should
|
19
|
+
it 'should return a Phony::NationalSplitters::Regex' do
|
20
|
+
dsl.match(/(123)/).class.name.should == Phony::NationalSplitters::Regex.name
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -22,8 +22,8 @@ describe Phony::LocalSplitters::Fixed do
|
|
22
22
|
it 'splits correctly' do
|
23
23
|
@splitter.split('3643532').should == ['364','35','32']
|
24
24
|
end
|
25
|
-
it 'splits correctly even when the number is too long' do
|
26
|
-
@splitter.split('3643532111').should == ['364','35','
|
25
|
+
it 'splits correctly even when the number is too long (but leniently)' do
|
26
|
+
@splitter.split('3643532111').should == ['364','35','32111']
|
27
27
|
end
|
28
28
|
it 'splits correctly even when the number is too short' do
|
29
29
|
@splitter.split('364353').should == ['364','35','3']
|
@@ -36,8 +36,8 @@ describe Phony::LocalSplitters::Fixed do
|
|
36
36
|
it 'splits correctly' do
|
37
37
|
@splitter.split('3643532').should == ['364','35','32']
|
38
38
|
end
|
39
|
-
it 'splits correctly even when the number is too long' do
|
40
|
-
@splitter.split('3643532111').should == ['364','35','
|
39
|
+
it 'splits correctly even when the number is too long (but leniently)' do
|
40
|
+
@splitter.split('3643532111').should == ['364','35','32111']
|
41
41
|
end
|
42
42
|
it 'splits correctly even when the number is too short' do
|
43
43
|
@splitter.split('364353').should == ['364','35','3']
|
@@ -1,7 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
main = self
|
4
|
+
|
3
5
|
describe Phony::LocalSplitters::Regex do
|
4
6
|
|
7
|
+
before do
|
8
|
+
load 'spec_helper_extensions.rb'
|
9
|
+
main.send :include, SpecHelperExtensions
|
10
|
+
end
|
11
|
+
|
5
12
|
describe 'instance_for' do
|
6
13
|
it 'does not cache' do
|
7
14
|
described_class.instance_for({}).should_not equal(described_class.instance_for({}))
|
@@ -12,7 +19,7 @@ describe Phony::LocalSplitters::Regex do
|
|
12
19
|
before(:each) do
|
13
20
|
# Norway as example.
|
14
21
|
#
|
15
|
-
@splitter = described_class.instance_for
|
22
|
+
@splitter = described_class.instance_for(/^[489].*$/ => [3,2,3], :fallback => [2,2,2,2])
|
16
23
|
end
|
17
24
|
it 'splits a number correctly' do
|
18
25
|
@splitter.split('21234567').should == ['21','23','45','67']
|
@@ -45,5 +52,46 @@ describe Phony::LocalSplitters::Regex do
|
|
45
52
|
performance_of { @splitter.split('91234567').should == ['912','34','567'] }.should < 0.00004
|
46
53
|
end
|
47
54
|
end
|
55
|
+
|
56
|
+
describe 'plausible?' do
|
57
|
+
let(:number) {['123', '456']}
|
58
|
+
let(:result) { local_splitter.plausible?(number) }
|
59
|
+
|
60
|
+
context 'Local splitter without mappings' do
|
61
|
+
let(:local_splitter) { described_class.instance_for({})}
|
62
|
+
it 'returns false' do
|
63
|
+
result.should be_falsey
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'Mapping does not exist for a number' do
|
68
|
+
let(:local_splitter) { described_class.instance_for(/\A5/ => [1,2,3])}
|
69
|
+
it 'returns false' do
|
70
|
+
result.should be_falsey
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "Mapping exists, but the length is greater" do
|
75
|
+
let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2])}
|
76
|
+
it 'returns false' do
|
77
|
+
result.should be_falsey
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "Mapping exists, but the length is less" do
|
82
|
+
let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2,3])}
|
83
|
+
it 'returns false' do
|
84
|
+
result.should be_falsey
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'Mapping exists and the length is equal' do
|
89
|
+
let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2,2])}
|
90
|
+
it 'returns true' do
|
91
|
+
result.should be_truthy
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
48
96
|
|
49
|
-
end
|
97
|
+
end
|
@@ -24,10 +24,10 @@ describe Phony::NationalCode do
|
|
24
24
|
@national = Phony::NationalCode.new national_splitter, local_splitter
|
25
25
|
end
|
26
26
|
it 'splits correctly' do
|
27
|
-
@national.split('443643532').should == [
|
27
|
+
@national.split('443643532').should == [nil, '44', '364', '35', '32']
|
28
28
|
end
|
29
29
|
it 'splits correctly' do
|
30
|
-
@national.split('44364353').should == [
|
30
|
+
@national.split('44364353').should == [nil, '44', '364', '35', '3']
|
31
31
|
end
|
32
32
|
it 'normalizes correctly' do
|
33
33
|
@national.normalize('044364353').should == '44364353'
|
@@ -44,10 +44,10 @@ describe Phony::NationalCode do
|
|
44
44
|
@national = Phony::NationalCode.new national_splitter, local_splitter
|
45
45
|
end
|
46
46
|
it 'splits correctly' do
|
47
|
-
@national.split('142278186').should == [
|
47
|
+
@national.split('142278186').should == [nil, '1', '42', '27', '81', '86']
|
48
48
|
end
|
49
49
|
it 'splits correctly' do
|
50
|
-
@national.split('14227818').should == [
|
50
|
+
@national.split('14227818').should == [nil, '1', '42', '27', '81', '8']
|
51
51
|
end
|
52
52
|
it 'normalizes correctly' do
|
53
53
|
@national.normalize('0142278186').should == '142278186'
|
@@ -56,36 +56,36 @@ describe Phony::NationalCode do
|
|
56
56
|
@national.normalize('142278186').should == '142278186'
|
57
57
|
end
|
58
58
|
end
|
59
|
-
context 'normalizing' do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
59
|
+
# context 'normalizing' do
|
60
|
+
# context 'false' do
|
61
|
+
# before(:each) do
|
62
|
+
# @national = Phony::NationalCode.new nil, nil, false
|
63
|
+
# end
|
64
|
+
# it 'normalizes an italian case correctly' do
|
65
|
+
# @national.normalize('0909709511').should == '0909709511'
|
66
|
+
# end
|
67
|
+
# end
|
68
|
+
# context 'true' do
|
69
|
+
# before(:each) do
|
70
|
+
# national_splitter = Phony::NationalSplitters::Fixed.instance_for 2
|
71
|
+
# local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
|
72
|
+
# @national = Phony::NationalCode.new national_splitter, local_splitter, true
|
73
|
+
# end
|
74
|
+
# it 'normalizes a swiss case correctly' do
|
75
|
+
# @national.normalize('044364353').should == '44364353'
|
76
|
+
# end
|
77
|
+
# end
|
78
|
+
# context 'nil (true)' do
|
79
|
+
# before(:each) do
|
80
|
+
# national_splitter = Phony::NationalSplitters::Fixed.instance_for 2
|
81
|
+
# local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
|
82
|
+
# @national = Phony::NationalCode.new national_splitter, local_splitter, nil
|
83
|
+
# end
|
84
|
+
# it 'normalizes a swiss case correctly' do
|
85
|
+
# @national.normalize('044364353').should == '44364353'
|
86
|
+
# end
|
87
|
+
# end
|
88
|
+
# end
|
89
89
|
end
|
90
90
|
|
91
91
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Phony::NationalSplitters::Default do
|
4
|
+
|
5
|
+
describe 'instance_for' do
|
6
|
+
it 'caches' do
|
7
|
+
described_class.instance_for.should equal(described_class.instance_for)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'with instance' do
|
12
|
+
let(:splitter) { described_class.instance_for }
|
13
|
+
|
14
|
+
describe 'split' do
|
15
|
+
it 'does only pretend split' do
|
16
|
+
splitter.split(:anything).should == [nil, :anything]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'plausible?' do
|
21
|
+
it 'is always plausible' do
|
22
|
+
splitter.plausible?(:anything, :anything).should be_truthy
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'length' do
|
27
|
+
it 'needs to be at least 3' do
|
28
|
+
splitter.length.should == 3
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|