phony 2.15.0 → 2.20.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.
- checksums.yaml +5 -5
- data/README.textile +35 -7
- data/lib/phony/config.rb +91 -0
- data/lib/phony/countries/argentina.rb +355 -0
- data/lib/phony/countries/austria.rb +34 -24
- data/lib/phony/countries/bangladesh.rb +2 -0
- data/lib/phony/countries/belarus.rb +2 -0
- data/lib/phony/countries/brazil.rb +6 -4
- data/lib/phony/countries/cambodia.rb +6 -4
- data/lib/phony/countries/china.rb +7 -2
- data/lib/phony/countries/croatia.rb +13 -16
- data/lib/phony/countries/georgia.rb +6 -4
- 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 +8 -3
- data/lib/phony/countries/ireland.rb +27 -23
- data/lib/phony/countries/italy.rb +30 -17
- 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 +5 -1
- 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 +24 -14
- data/lib/phony/countries/saudi_arabia.rb +40 -0
- data/lib/phony/countries/serbia.rb +10 -4
- data/lib/phony/countries/somalia.rb +5 -1
- data/lib/phony/countries/south_korea.rb +16 -9
- data/lib/phony/countries/sweden.rb +53 -38
- data/lib/phony/countries/taiwan.rb +22 -46
- data/lib/phony/countries/tajikistan.rb +2 -0
- data/lib/phony/countries/turkmenistan.rb +2 -0
- data/lib/phony/countries/ukraine.rb +5 -2
- data/lib/phony/countries/united_kingdom.rb +5 -2
- data/lib/phony/countries/uruguay.rb +2 -0
- data/lib/phony/countries/vietnam.rb +94 -92
- data/lib/phony/countries/zimbabwe.rb +2 -0
- data/lib/phony/countries.rb +210 -98
- data/lib/phony/country.rb +15 -3
- data/lib/phony/country_codes.rb +17 -4
- 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 -4
- data/lib/phony/vanity.rb +1 -1
- data/lib/phony.rb +94 -59
- data/spec/functional/config_spec.rb +44 -0
- data/spec/functional/plausibility_spec.rb +373 -35
- data/spec/lib/phony/countries_spec.rb +295 -63
- data/spec/lib/phony/country_codes_spec.rb +106 -33
- data/spec/lib/phony/country_spec.rb +54 -15
- data/spec/lib/phony/dsl_spec.rb +2 -2
- data/spec/lib/phony/local_splitters/regex_spec.rb +12 -5
- data/spec/lib/phony/national_splitters/default_spec.rb +1 -1
- data/spec/lib/phony/trunk_code_spec.rb +85 -0
- data/spec/lib/phony/vanity_spec.rb +30 -0
- data/spec/lib/phony_spec.rb +70 -0
- metadata +27 -17
@@ -1,106 +1,179 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Phony::CountryCodes do
|
4
|
+
|
5
|
+
let(:countries) { Phony::CountryCodes.instance }
|
6
|
+
|
7
|
+
describe '#plausible?' do
|
8
|
+
it 'raises an error on a too long ccc' do
|
9
|
+
expect do
|
10
|
+
countries.plausible?('+1 868 7620266', ccc: '1868123')
|
11
|
+
end.to raise_error(ArgumentError, %Q{The provided ccc option is too long and includes more than a cc ('1') and ndc ('868'). It also includes '123'.})
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'ccc handling' do
|
16
|
+
it 'splits a ccc correctly' do
|
17
|
+
cc, ndc, *local = countries.split('1868')
|
18
|
+
cc.should eq('1')
|
19
|
+
ndc.should eq('868')
|
20
|
+
end
|
21
|
+
it 'splits a ccc correctly' do
|
22
|
+
cc, ndc, *local = countries.split('1868')
|
23
|
+
cc.should eq('1')
|
24
|
+
ndc.should eq('868')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#[]' do
|
29
|
+
it 'returns a country' do
|
30
|
+
countries['41'].class.should eql Phony::Country
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#country_for' do
|
35
|
+
it 'returns a country' do
|
36
|
+
countries.send(:country_for, '41').class.should eql Phony::Country
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#countrify' do
|
41
|
+
it 'returns a country' do
|
42
|
+
countries.send(:countrify, '441231212', '41').should eql '41441231212'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
describe '#countrify!' do
|
46
|
+
it 'in-place replaces the number' do
|
47
|
+
number = '441231212'
|
48
|
+
countries.send(:countrify!, number, '41').should eql number
|
49
|
+
|
50
|
+
number.should == '41441231212'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#vanity?' do
|
55
|
+
it 'returns true if so' do
|
56
|
+
countries.vanity?('1800HELLOES').should eql true
|
57
|
+
end
|
58
|
+
it 'returns false if not' do
|
59
|
+
countries.vanity?('18001234567').should eql false
|
60
|
+
end
|
61
|
+
end
|
4
62
|
|
5
|
-
|
6
|
-
|
63
|
+
describe 'normalize' do
|
64
|
+
it 'normalizes correctly' do
|
65
|
+
countries.normalize('0041-44-364-35-32').should eql '41443643532'
|
66
|
+
end
|
67
|
+
it 'normalizes correctly with CC option' do
|
68
|
+
countries.normalize('044-364-35-32', cc: '41').should eql '41443643532'
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'specific countries' do
|
72
|
+
it 'handles Congo correctly' do
|
73
|
+
countries.normalize('+242 0571 73992').should eql '242057173992'
|
74
|
+
countries.normalize('+242 2221 15932').should eql '242222115932'
|
75
|
+
end
|
76
|
+
end
|
7
77
|
end
|
8
78
|
|
9
79
|
describe 'formatted' do
|
10
80
|
it 'formats correctly' do
|
11
|
-
|
81
|
+
countries.formatted('41443643532', :format => :international, :spaces => :-).should eql '+41-44-364-35-32'
|
12
82
|
end
|
13
83
|
it 'formats correctly' do
|
14
|
-
|
84
|
+
countries.formatted('41443643532', :format => :international_relative, :spaces => :-).should eql '0041-44-364-35-32'
|
15
85
|
end
|
16
86
|
it 'formats correctly' do
|
17
|
-
|
87
|
+
countries.formatted('41443643532', :format => :national, :spaces => :-).should eql '044-364-35-32'
|
18
88
|
end
|
19
89
|
context 'specific' do
|
20
90
|
it 'formats Ireland correctly' do
|
21
|
-
|
91
|
+
countries.formatted("3533451234", :format => :national).should eql '0345 1234'
|
22
92
|
end
|
23
93
|
it 'formats Ireland correctly' do
|
24
|
-
|
94
|
+
countries.formatted("353411231234", :format => :national).should eql '041 123 1234'
|
25
95
|
end
|
26
96
|
it 'formats Spain correctly' do
|
27
|
-
|
97
|
+
countries.formatted("34123456789", :format => :national).should eql '123 456 789'
|
28
98
|
end
|
29
99
|
it 'formats Cambodia correctly' do
|
30
|
-
|
100
|
+
countries.formatted('85512239123', :format => :national).should eql '012 239 123'
|
31
101
|
end
|
32
102
|
it 'formats the US correctly' do
|
33
|
-
|
103
|
+
countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
|
34
104
|
end
|
35
105
|
it 'formats the US correctly' do
|
36
|
-
|
106
|
+
countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
|
37
107
|
end
|
38
108
|
end
|
39
109
|
context 'default' do
|
40
110
|
it "should format swiss numbers" do
|
41
|
-
|
111
|
+
countries.formatted('41443643532').should eql '+41 44 364 35 32'
|
42
112
|
end
|
43
113
|
it "should format swiss service numbers" do
|
44
|
-
|
114
|
+
countries.formatted('41800112233').should eql '+41 800 112 233'
|
45
115
|
end
|
46
116
|
it "should format austrian numbers" do
|
47
|
-
|
117
|
+
countries.formatted('43198110').should eql '+43 1 98110'
|
48
118
|
end
|
49
119
|
it "should format american numbers" do
|
50
|
-
|
120
|
+
countries.formatted('18705551122').should eql '+1 (870) 555-1122'
|
51
121
|
end
|
52
122
|
it "should format irish numbers" do
|
53
|
-
|
123
|
+
countries.formatted('35311234567').should eql '+353 1 123 4567'
|
54
124
|
end
|
55
125
|
end
|
56
126
|
describe "international" do
|
57
127
|
it "should format north american numbers" do
|
58
|
-
|
128
|
+
countries.formatted('18091231234', :format => :international).should eql '+1 (809) 123-1234'
|
59
129
|
end
|
60
130
|
it "should format austrian numbers" do
|
61
|
-
|
131
|
+
countries.formatted('43198110', :format => :international).should eql '+43 1 98110'
|
62
132
|
end
|
63
133
|
it "should format austrian numbers" do
|
64
|
-
|
134
|
+
countries.formatted('43198110', :format => :international_absolute).should eql '+43 1 98110'
|
65
135
|
end
|
66
136
|
it "should format french numbers" do
|
67
|
-
|
137
|
+
countries.formatted('33142278186', :format => :+).should eql '+33 1 42 27 81 86'
|
68
138
|
end
|
69
139
|
it "should format austrian numbers" do
|
70
|
-
|
140
|
+
countries.formatted('43198110', :format => :international_relative).should eql '0043 1 98110'
|
71
141
|
end
|
72
142
|
it 'should format liechtensteiner numbers' do
|
73
|
-
|
143
|
+
countries.formatted('4233841148', :format => :international_relative).should eql '00423 384 11 48'
|
74
144
|
end
|
75
145
|
it "should format irish numbers" do
|
76
|
-
|
146
|
+
countries.formatted('35311234567', :format => :international).should eql '+353 1 123 4567'
|
77
147
|
end
|
78
148
|
it "should format luxembourgian numbers" do
|
79
|
-
|
149
|
+
countries.formatted('352222809', :format => :international).should eql '+352 22 28 09'
|
80
150
|
end
|
81
151
|
it "should format luxembourgian 4-digit ndc numbers" do
|
82
|
-
|
152
|
+
countries.formatted('35226222809', :format => :international).should eql '+352 2622 28 09'
|
83
153
|
end
|
84
154
|
it "should format luxembourgian mobile numbers" do
|
85
|
-
|
155
|
+
countries.formatted('352621123456', :format => :international).should eql '+352 621 123 456'
|
86
156
|
end
|
87
157
|
it "should format luxembourgian city numbers" do
|
88
|
-
|
158
|
+
countries.formatted('3524123456', :format => :international).should eql '+352 41 23 45 6'
|
89
159
|
end
|
90
160
|
it "should format luxembourgian machine to machine numbers" do
|
91
|
-
|
161
|
+
countries.formatted('352602112345678', :format => :international).should eql '+352 6021 12 34 56 78'
|
92
162
|
end
|
93
163
|
it "should format luxembourgian numbers" do
|
94
|
-
|
164
|
+
countries.formatted('352370431', :format => :international).should eql '+352 37 04 31'
|
95
165
|
end
|
96
166
|
it "should format luxembourgian numbers" do
|
97
|
-
|
167
|
+
countries.formatted('35227855', :format => :international).should eql '+352 27 85 5'
|
168
|
+
end
|
169
|
+
it "should format nigerian lagosian numbers" do
|
170
|
+
countries.formatted('23414480000', :format => :international).should eql '+234 1 448 0000'
|
98
171
|
end
|
99
|
-
it "should format nigerian numbers" do
|
100
|
-
|
172
|
+
it "should format nigerian beninese numbers" do
|
173
|
+
countries.formatted('23452123456', :format => :international).should eql '+234 52 123 456'
|
101
174
|
end
|
102
175
|
it "should format nigerian mobile numbers" do
|
103
|
-
|
176
|
+
countries.formatted('2347061234567', :format => :international).should eql '+234 706 123 4567'
|
104
177
|
end
|
105
178
|
context 'with no spaces' do
|
106
179
|
it "should format north american numbers" do
|
@@ -2,45 +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
|
-
|
27
|
-
@switzerland.with '41' # TODO Remove this kludge.
|
66
|
+
Phony::Country.new national_code
|
28
67
|
end
|
29
68
|
|
30
69
|
describe "split" do
|
31
70
|
it "should handle ZH" do
|
32
|
-
|
71
|
+
country.split('443643532').should == [nil, '44', '364', '35', '32']
|
33
72
|
end
|
34
73
|
end
|
35
74
|
describe 'normalize' do
|
36
75
|
it "should handle ZH" do
|
37
|
-
|
76
|
+
country.normalize('0443643532').should == '443643532'
|
38
77
|
end
|
39
78
|
end
|
40
79
|
end
|
41
80
|
|
42
81
|
context "without special cases" do
|
43
|
-
|
82
|
+
let(:country) do
|
44
83
|
special_national_splitter = Phony::NationalSplitters::Variable.new nil, ['800']
|
45
84
|
special_local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 3]
|
46
85
|
special_code = Phony::NationalCode.new special_national_splitter, special_local_splitter
|
@@ -49,17 +88,17 @@ describe Phony::Country do
|
|
49
88
|
local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
|
50
89
|
national_code = Phony::NationalCode.new national_splitter, local_splitter
|
51
90
|
|
52
|
-
|
91
|
+
Phony::Country.new special_code, national_code
|
53
92
|
end
|
54
93
|
|
55
94
|
describe "split" do
|
56
95
|
it "should handle ZH" do
|
57
|
-
|
96
|
+
country.split('443643532').should == [nil, '44', '364', '35', '32']
|
58
97
|
end
|
59
98
|
it "should handle 800" do
|
60
|
-
|
99
|
+
country.split('800333666').should == [nil, '800', '333', '666']
|
61
100
|
end
|
62
101
|
end
|
63
102
|
end
|
64
103
|
|
65
|
-
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
|
|
@@ -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({}))
|
@@ -53,35 +60,35 @@ describe Phony::LocalSplitters::Regex do
|
|
53
60
|
context 'Local splitter without mappings' do
|
54
61
|
let(:local_splitter) { described_class.instance_for({})}
|
55
62
|
it 'returns false' do
|
56
|
-
result.should
|
63
|
+
result.should be_falsey
|
57
64
|
end
|
58
65
|
end
|
59
66
|
|
60
67
|
context 'Mapping does not exist for a number' do
|
61
68
|
let(:local_splitter) { described_class.instance_for(/\A5/ => [1,2,3])}
|
62
69
|
it 'returns false' do
|
63
|
-
result.should
|
70
|
+
result.should be_falsey
|
64
71
|
end
|
65
72
|
end
|
66
73
|
|
67
74
|
context "Mapping exists, but the length is greater" do
|
68
75
|
let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2])}
|
69
76
|
it 'returns false' do
|
70
|
-
result.should
|
77
|
+
result.should be_falsey
|
71
78
|
end
|
72
79
|
end
|
73
80
|
|
74
81
|
context "Mapping exists, but the length is less" do
|
75
82
|
let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2,3])}
|
76
83
|
it 'returns false' do
|
77
|
-
result.should
|
84
|
+
result.should be_falsey
|
78
85
|
end
|
79
86
|
end
|
80
87
|
|
81
88
|
context 'Mapping exists and the length is equal' do
|
82
89
|
let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2,2])}
|
83
90
|
it 'returns true' do
|
84
|
-
result.should
|
91
|
+
result.should be_truthy
|
85
92
|
end
|
86
93
|
end
|
87
94
|
|
@@ -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
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Phony::Vanity do
|
6
|
+
|
7
|
+
let(:vanity) { described_class }
|
8
|
+
|
9
|
+
describe '.replace' do
|
10
|
+
it 'replaces letters with digits' do
|
11
|
+
vanity.replace('1-800-HELLO').should == '1-800-43556'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.vanity?' do
|
16
|
+
it 'returns true on a vanity number' do
|
17
|
+
vanity.vanity?('800HELLOES').should == true
|
18
|
+
end
|
19
|
+
it 'returns false on a non-vanity number' do
|
20
|
+
vanity.vanity?('8004355637').should == false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.normalized' do
|
25
|
+
it 'normalizes the vanity number' do
|
26
|
+
vanity.normalized('1-800-HELLO').should == '1800HELLO'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Phony::NormalizationError do
|
4
|
+
it 'is correctly raised on normalize' do
|
5
|
+
expect do
|
6
|
+
Phony.normalize('000')
|
7
|
+
end.to raise_error(Phony::NormalizationError)
|
8
|
+
end
|
9
|
+
it 'is correctly raised on normalize' do
|
10
|
+
expect do
|
11
|
+
Phony.normalize('000')
|
12
|
+
end.to raise_error(%Q{Phony could not normalize the given number. Is it a phone number?})
|
13
|
+
end
|
14
|
+
it 'is correctly raised on normalize!' do
|
15
|
+
expect do
|
16
|
+
Phony.normalize!('000')
|
17
|
+
end.to raise_error(Phony::NormalizationError)
|
18
|
+
end
|
19
|
+
it 'is correctly raised on normalize!' do
|
20
|
+
expect do
|
21
|
+
Phony.normalize!('000')
|
22
|
+
end.to raise_error(%Q{Phony could not normalize the given number. Is it a phone number?})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe Phony::SplittingError do
|
27
|
+
it 'is correctly raised on split' do
|
28
|
+
expect do
|
29
|
+
Phony.split('000')
|
30
|
+
end.to raise_error(Phony::SplittingError)
|
31
|
+
end
|
32
|
+
it 'is correctly raised on split' do
|
33
|
+
expect do
|
34
|
+
Phony.split('000')
|
35
|
+
end.to raise_error(%Q{Phony could not split the given number. Is "000" a phone number?})
|
36
|
+
end
|
37
|
+
it 'is correctly raised on split!' do
|
38
|
+
expect do
|
39
|
+
Phony.split!('000')
|
40
|
+
end.to raise_error(Phony::SplittingError)
|
41
|
+
end
|
42
|
+
it 'is correctly raised on split!' do
|
43
|
+
expect do
|
44
|
+
Phony.split!('000')
|
45
|
+
end.to raise_error(%Q{Phony could not split the given number. Is it a phone number?})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe Phony::FormattingError do
|
50
|
+
it 'is correctly raised on format' do
|
51
|
+
expect do
|
52
|
+
Phony.format('000')
|
53
|
+
end.to raise_error(Phony::FormattingError)
|
54
|
+
end
|
55
|
+
it 'is correctly raised on format' do
|
56
|
+
expect do
|
57
|
+
Phony.format('000')
|
58
|
+
end.to raise_error(%Q{Phony could not format the given number. Is it a phone number?})
|
59
|
+
end
|
60
|
+
it 'is correctly raised on format!' do
|
61
|
+
expect do
|
62
|
+
Phony.format!('000')
|
63
|
+
end.to raise_error(Phony::FormattingError)
|
64
|
+
end
|
65
|
+
it 'is correctly raised on format!' do
|
66
|
+
expect do
|
67
|
+
Phony.format!('000')
|
68
|
+
end.to raise_error(%Q{Phony could not format the given number. Is it a phone number?})
|
69
|
+
end
|
70
|
+
end
|