phony 1.9.0 → 2.19.14
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -16,13 +16,16 @@ describe Phony::NationalSplitters::Fixed do
|
|
16
16
|
@splitter = Phony::NationalSplitters::Fixed.new 2
|
17
17
|
end
|
18
18
|
it 'splits correctly' do
|
19
|
-
@splitter.split('443643532').should == [
|
19
|
+
@splitter.split('443643532').should == [nil, '44', '3643532']
|
20
20
|
end
|
21
21
|
it 'splits correctly even when the number is too long' do
|
22
|
-
@splitter.split('44364353211').should == [
|
22
|
+
@splitter.split('44364353211').should == [nil, '44', '364353211']
|
23
23
|
end
|
24
24
|
it 'splits correctly even when the number is too short' do
|
25
|
-
@splitter.split('443').should == [
|
25
|
+
@splitter.split('443').should == [nil, '44','3']
|
26
|
+
end
|
27
|
+
it 'has a length of 2' do
|
28
|
+
@splitter.length.should == 2
|
26
29
|
end
|
27
30
|
end
|
28
31
|
describe 'split' do
|
@@ -30,13 +33,16 @@ describe Phony::NationalSplitters::Fixed do
|
|
30
33
|
@splitter = Phony::NationalSplitters::Fixed.new nil
|
31
34
|
end
|
32
35
|
it 'splits correctly' do
|
33
|
-
@splitter.split('443643532').should == [
|
36
|
+
@splitter.split('443643532').should == [nil, '443643532']
|
34
37
|
end
|
35
38
|
it 'splits correctly even when the number is too long' do
|
36
|
-
@splitter.split('44364353211').should == [
|
39
|
+
@splitter.split('44364353211').should == [nil, '44364353211']
|
37
40
|
end
|
38
41
|
it 'splits correctly even when the number is too short' do
|
39
|
-
@splitter.split('443').should == [
|
42
|
+
@splitter.split('443').should == [nil, '443']
|
43
|
+
end
|
44
|
+
it 'has a length of nil' do
|
45
|
+
@splitter.length.should == nil
|
40
46
|
end
|
41
47
|
end
|
42
48
|
|
@@ -8,11 +8,21 @@ describe Phony::NationalSplitters::None do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
context 'with instance' do
|
12
12
|
let(:splitter) { described_class.instance_for }
|
13
|
-
|
14
|
-
|
13
|
+
|
14
|
+
describe 'split' do
|
15
|
+
it 'splits correctly into ndc and rest' do
|
16
|
+
splitter.split('123456789').should == [nil, false, '123456789']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'length' do
|
21
|
+
it 'is always 0' do
|
22
|
+
splitter.length.should be_zero
|
23
|
+
end
|
15
24
|
end
|
25
|
+
|
16
26
|
end
|
17
27
|
|
18
28
|
end
|
@@ -15,7 +15,7 @@ describe Phony::NationalSplitters::Regex do
|
|
15
15
|
context 'with on_fail 2' do
|
16
16
|
let(:splitter) { described_class.instance_for(/^(123)\d+$/, 2) }
|
17
17
|
it 'uses the on_fail_take' do
|
18
|
-
splitter.split('23456789').should == [
|
18
|
+
splitter.split('23456789').should == [nil, '23', '456789']
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -8,16 +8,19 @@ describe Phony::NationalSplitters::Variable do
|
|
8
8
|
@splitter = Phony::NationalSplitters::Variable.new 4, ['1', '316', '67', '68', '669', '711']
|
9
9
|
end
|
10
10
|
it "handles Vienna" do
|
11
|
-
@splitter.split('198110').should == [
|
11
|
+
@splitter.split('198110').should == [nil, '1', '98110']
|
12
12
|
end
|
13
13
|
it "handles some mobile services" do
|
14
|
-
@splitter.split('66914093902').should == [
|
14
|
+
@splitter.split('66914093902').should == [nil, '669', '14093902']
|
15
15
|
end
|
16
16
|
it "handles Graz" do
|
17
|
-
@splitter.split('3161234567891').should == [
|
17
|
+
@splitter.split('3161234567891').should == [nil, '316', '1234567891']
|
18
18
|
end
|
19
19
|
it "handles Rohrau" do
|
20
|
-
@splitter.split('2164123456789').should == [
|
20
|
+
@splitter.split('2164123456789').should == [nil, '2164', '123456789']
|
21
|
+
end
|
22
|
+
it 'has an NDC length of 3' do
|
23
|
+
@splitter.length.should == (1..3)
|
21
24
|
end
|
22
25
|
end
|
23
26
|
context 'special handling for using the variable size splitter for Swiss service numbers' do
|
@@ -25,7 +28,10 @@ describe Phony::NationalSplitters::Variable do
|
|
25
28
|
@splitter = Phony::NationalSplitters::Variable.new 2, ['800']
|
26
29
|
end
|
27
30
|
it "should handle swiss service numbers" do
|
28
|
-
@splitter.split('800223344').should == [
|
31
|
+
@splitter.split('800223344').should == [nil, '800', '223344']
|
32
|
+
end
|
33
|
+
it 'has an NDC length of 3' do
|
34
|
+
@splitter.length.should == (3..3)
|
29
35
|
end
|
30
36
|
end
|
31
37
|
end
|
@@ -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
|
@@ -4,31 +4,27 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Phony::Vanity do
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Phony::Vanity.vanity?('444443322').should == false
|
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'
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|
16
|
-
describe
|
17
|
-
it '
|
18
|
-
|
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
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
|
-
describe '
|
23
|
-
it '
|
24
|
-
|
25
|
-
end
|
26
|
-
it 'returns the right thing' do
|
27
|
-
Phony::Vanity.mapping.should == [
|
28
|
-
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.freeze,
|
29
|
-
'2223334445556667777888999922233344455566677778889999'.freeze
|
30
|
-
]
|
24
|
+
describe '.normalized' do
|
25
|
+
it 'normalizes the vanity number' do
|
26
|
+
vanity.normalized('1-800-HELLO').should == '1800HELLO'
|
31
27
|
end
|
32
28
|
end
|
33
|
-
|
29
|
+
|
34
30
|
end
|
data/spec/lib/phony_spec.rb
CHANGED
@@ -1,288 +1,70 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
|
-
describe Phony do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Phony.normalize(nil)
|
11
|
-
}.to raise_error(ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.normalize(number).")
|
12
|
-
end
|
13
|
-
it "should raise on format nil" do
|
14
|
-
expect {
|
15
|
-
Phony.format(nil)
|
16
|
-
}.to raise_error(ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.format(number).")
|
17
|
-
end
|
18
|
-
it "should raise on split nil" do
|
19
|
-
expect {
|
20
|
-
Phony.split(nil)
|
21
|
-
}.to raise_error(ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.split(number).")
|
22
|
-
end
|
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)
|
23
8
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
Phony.normalize('+972').should == '972'
|
29
|
-
end
|
30
|
-
it "should normalize an already normalized number" do
|
31
|
-
Phony.normalize('41443643533').should == '41443643533'
|
32
|
-
end
|
33
|
-
it "should normalize a format number" do
|
34
|
-
Phony.normalize('+41 44 364 35 33').should == '41443643533'
|
35
|
-
end
|
36
|
-
it "should normalize a 00 number" do
|
37
|
-
Phony.normalize('0041 44 364 35 33').should == '41443643533'
|
38
|
-
end
|
39
|
-
it "should normalize a service number" do
|
40
|
-
Phony.normalize('+41 800 11 22 33').should == '41800112233'
|
41
|
-
end
|
42
|
-
it "should remove characters from the number" do
|
43
|
-
Phony.normalize('John: +41 44 364 35 33').should == '41443643533'
|
44
|
-
end
|
45
|
-
it "should normalize one of these crazy american numbers" do
|
46
|
-
Phony.normalize('1 (703) 451-5115').should == '17034515115'
|
47
|
-
end
|
48
|
-
it "should normalize another one of these crazy american numbers" do
|
49
|
-
Phony.normalize('1-888-407-4747').should == '18884074747'
|
50
|
-
end
|
51
|
-
it "should normalize a number with colons" do
|
52
|
-
Phony.normalize('1.906.387.1698').should == '19063871698'
|
53
|
-
end
|
54
|
-
it "should normalize a number with optional ndc" do
|
55
|
-
Phony.normalize('+41 (044) 364 35 33').should == '41443643533'
|
56
|
-
end
|
57
|
-
it "should normalize a number with erroneous zero inside" do
|
58
|
-
Phony.normalize('+410443643533').should == '41443643533'
|
59
|
-
end
|
60
|
-
it "should not normalize a number with a correct zero inside" do
|
61
|
-
Phony.normalize('+390909709511').should == '390909709511'
|
62
|
-
end
|
63
|
-
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?})
|
64
13
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
14
|
+
it 'is correctly raised on normalize!' do
|
15
|
+
expect do
|
16
|
+
Phony.normalize!('000')
|
17
|
+
end.to raise_error(Phony::NormalizationError)
|
70
18
|
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
Phony.format('41443643532').should == '+41 44 364 35 32'
|
76
|
-
end
|
77
|
-
# TODO
|
78
|
-
#
|
79
|
-
it "should format swiss service numbers" do
|
80
|
-
Phony.format('41800112233').should == '+41 800 112 233'
|
81
|
-
end
|
82
|
-
it "should format austrian numbers" do
|
83
|
-
Phony.format('43198110').should == '+43 1 98110'
|
84
|
-
end
|
85
|
-
it "should format american numbers" do
|
86
|
-
Phony.format('18705551122').should == '+1 870 555 1122'
|
87
|
-
end
|
88
|
-
end
|
89
|
-
describe "international" do
|
90
|
-
it "should format north american numbers" do
|
91
|
-
Phony.format('18091231234', :format => :international).should == '+1 809 123 1234'
|
92
|
-
end
|
93
|
-
it "should format austrian numbers" do
|
94
|
-
Phony.format('43198110', :format => :international).should == '+43 1 98110'
|
95
|
-
end
|
96
|
-
it "should format austrian numbers" do
|
97
|
-
Phony.format('43198110', :format => :international_absolute).should == '+43 1 98110'
|
98
|
-
end
|
99
|
-
it "should format french numbers" do
|
100
|
-
Phony.format('33142278186', :format => :+).should == '+33 1 42 27 81 86'
|
101
|
-
end
|
102
|
-
it "should format austrian numbers" do
|
103
|
-
Phony.format('43198110', :format => :international_relative).should == '0043 1 98110'
|
104
|
-
end
|
105
|
-
it 'should format liechtensteiner numbers' do
|
106
|
-
Phony.format('4233841148', :format => :international_relative).should == '00423 384 11 48'
|
107
|
-
end
|
108
|
-
context 'with no spaces' do
|
109
|
-
it "should format north american numbers" do
|
110
|
-
Phony.format('18091231234', :format => :international, :spaces => '').should == '+18091231234'
|
111
|
-
end
|
112
|
-
it "should format austrian numbers" do
|
113
|
-
Phony.format('43198110', :format => :international, :spaces => '').should == '+43198110'
|
114
|
-
end
|
115
|
-
it "should format austrian numbers" do
|
116
|
-
Phony.format('43198110', :format => :international_absolute, :spaces => '').should == '+43198110'
|
117
|
-
end
|
118
|
-
it "should format french numbers" do
|
119
|
-
Phony.format('33142278186', :format => :+, :spaces => '').should == '+33142278186'
|
120
|
-
end
|
121
|
-
it "should format austrian numbers" do
|
122
|
-
Phony.format('43198110', :format => :international_relative, :spaces => '').should == '0043198110'
|
123
|
-
end
|
124
|
-
it 'should format liechtensteiner numbers' do
|
125
|
-
Phony.format('4233841148', :format => :international_relative, :spaces => '').should == '004233841148'
|
126
|
-
end
|
127
|
-
end
|
128
|
-
context 'with special spaces' do
|
129
|
-
it "should format swiss numbers" do
|
130
|
-
Phony.format('41443643532', :format => :international).should == '+41 44 364 35 32'
|
131
|
-
end
|
132
|
-
it "should format north american numbers" do
|
133
|
-
Phony.format('18091231234', :format => :international, :spaces => :-).should == '+1-809-123-1234'
|
134
|
-
end
|
135
|
-
it "should format austrian numbers" do
|
136
|
-
Phony.format('43198110', :format => :international, :spaces => :-).should == '+43-1-98110'
|
137
|
-
end
|
138
|
-
it "should format austrian numbers" do
|
139
|
-
Phony.format('43198110', :format => :international_absolute, :spaces => :-).should == '+43-1-98110'
|
140
|
-
end
|
141
|
-
it "should format french numbers" do
|
142
|
-
Phony.format('33142278186', :format => :+, :spaces => :-).should == '+33-1-42-27-81-86'
|
143
|
-
end
|
144
|
-
it "should format austrian numbers" do
|
145
|
-
Phony.format('43198110', :format => :international_relative, :spaces => :-).should == '0043-1-98110'
|
146
|
-
end
|
147
|
-
it 'should format liechtensteiner numbers' do
|
148
|
-
Phony.format('4233841148', :format => :international_relative, :spaces => :-).should == '00423-384-11-48'
|
149
|
-
end
|
150
|
-
end
|
151
|
-
describe '"unsupported" countries' do
|
152
|
-
it 'should format as a single block' do
|
153
|
-
Phony.format('88032155605220').should == '+880 32155605220'
|
154
|
-
end
|
155
|
-
it 'should format as a single block, regardless of format' do
|
156
|
-
Phony.format('8801819372205', :format => :international).should == '+880 1819372205'
|
157
|
-
end
|
158
|
-
it 'should format as a single block, respecting custom spaces' do
|
159
|
-
Phony.format('8801819372205', :spaces => :-).should == '+880-1819372205'
|
160
|
-
end
|
161
|
-
it 'should format as a single block, even without spaces' do
|
162
|
-
Phony.format('8801819372205', :spaces => '').should == '+8801819372205'
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
describe "national" do
|
167
|
-
it "should format swiss numbers" do
|
168
|
-
Phony.format('41443643532', :format => :national).should == '044 364 35 32'
|
169
|
-
end
|
170
|
-
# TODO
|
171
|
-
#
|
172
|
-
it "should format swiss service numbers" do
|
173
|
-
Phony.format('41800112233', :format => :national).should == '0800 112 233'
|
174
|
-
end
|
175
|
-
it "should format austrian numbers" do
|
176
|
-
Phony.format('43198110', :format => :national).should == '01 98110'
|
177
|
-
end
|
178
|
-
it "should format US numbers without a leading zero" do
|
179
|
-
Phony.format('14159224711', :format => :national).should == '415 922 4711'
|
180
|
-
end
|
181
|
-
end
|
182
|
-
describe "local" do
|
183
|
-
it "should format swiss numbers" do
|
184
|
-
Phony.format('41443643532', :format => :local).should == '364 35 32'
|
185
|
-
end
|
186
|
-
it "should format german numbers" do
|
187
|
-
Phony.format('493038625454', :format => :local).should == '386 25454'
|
188
|
-
end
|
189
|
-
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?})
|
190
23
|
end
|
24
|
+
end
|
191
25
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
end
|
198
|
-
context 'splitting' do
|
199
|
-
it 'handles completely missing numbers well enough' do
|
200
|
-
Phony.split('4144').should == ['41', '44', '']
|
201
|
-
end
|
202
|
-
it 'handles a missing number part' do
|
203
|
-
Phony.split('4144364').should == ['41', '44', '364']
|
204
|
-
end
|
205
|
-
it 'handles a missing number part' do
|
206
|
-
Phony.split('414436435').should == ['41', '44', '364', '35']
|
207
|
-
end
|
208
|
-
end
|
209
|
-
context 'formatting' do
|
210
|
-
it 'handles completely missing numbers well enough' do
|
211
|
-
Phony.format('4144').should == '+41 44 '
|
212
|
-
end
|
213
|
-
it 'handles a missing number part' do
|
214
|
-
Phony.format('4144364').should == '+41 44 364'
|
215
|
-
end
|
216
|
-
it 'handles a missing number part' do
|
217
|
-
Phony.format('414436435').should == '+41 44 364 35'
|
218
|
-
end
|
219
|
-
end
|
220
|
-
context '"unsupported" countries' do
|
221
|
-
it 'handles formatting' do
|
222
|
-
Phony.format('88032155605220').should == '+880 32155605220'
|
223
|
-
end
|
224
|
-
it 'handles normalizing' do
|
225
|
-
Phony.normalize('+880-321 5560 5220').should == '88032155605220'
|
226
|
-
end
|
227
|
-
end
|
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)
|
228
31
|
end
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
'41443643532',
|
234
|
-
'18091231234',
|
235
|
-
'43198110',
|
236
|
-
'33142278186',
|
237
|
-
'4233841148'
|
238
|
-
]
|
239
|
-
end
|
240
|
-
describe 'split' do
|
241
|
-
it 'is fast' do
|
242
|
-
number = @phone_numbers.first
|
243
|
-
performance_of { Phony.split(number) }.should < 0.00005
|
244
|
-
end
|
245
|
-
it 'is fast' do
|
246
|
-
performance_of { @phone_numbers.each { |number| Phony.split(number) } }.should < 0.00015
|
247
|
-
end
|
248
|
-
end
|
249
|
-
describe 'normalize' do
|
250
|
-
it 'is fast' do
|
251
|
-
number = @phone_numbers.first
|
252
|
-
performance_of { Phony.normalize(number) }.should < 0.0001
|
253
|
-
end
|
254
|
-
it 'is fast' do
|
255
|
-
performance_of { @phone_numbers.each { |number| Phony.normalize(number) } }.should < 0.00016
|
256
|
-
end
|
257
|
-
end
|
258
|
-
describe 'format' do
|
259
|
-
it 'is fast' do
|
260
|
-
number = @phone_numbers.first
|
261
|
-
performance_of { Phony.format(number) }.should < 0.000075
|
262
|
-
end
|
263
|
-
it 'is fast' do
|
264
|
-
performance_of { @phone_numbers.each { |number| Phony.format(number) } }.should < 0.00016
|
265
|
-
end
|
266
|
-
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?})
|
267
36
|
end
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
end
|
278
|
-
|
279
|
-
describe 'vanity_to_number' do
|
280
|
-
it {Phony.vanity_to_number('41800WEGGLI').should == '41800934454'}
|
281
|
-
it {Phony.vanity_to_number('41800weggli').should == '41800934454'}
|
282
|
-
# it {Phony.vanity_to_number('41800SUCCESSMATCH').should == '41800782237'} # Cut off according to the swiss norms.
|
283
|
-
it {Phony.vanity_to_number('41800SUCCESSMATCH').should == '41800782237762824'} # Allow for call-through numbers (>= 1.6.0)
|
284
|
-
it {Phony.vanity_to_number('4180BLA').should == '4180252'} # Does not check for validity of number.
|
285
|
-
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?})
|
286
46
|
end
|
287
|
-
|
288
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
|