phony 2.5.1 → 2.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/phony/countries/cambodia.rb +1 -1
- data/spec/functional/normalize_spec.rb +93 -1
- data/spec/lib/phony/country_codes_spec.rb +14 -11
- data/spec/lib/phony_spec.rb +0 -92
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjgyNzBkYTU1NDg4NDE3OWNjZjU3YzVmODc3MWY2MjBlNTRkY2E4NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2U4YTMxNWM1NjA4ZTI4MjM0MWMxMzRlYTg4MDA0YmRmMzEyOGVkNg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWQ4YTI5Y2I0NDFhZDgyNjE5NDIyNjc0MWUyZjQyNTAwMzRlYWM4NmNkYmNi
|
10
|
+
MGE0ZThmOTk2NWM3YzRhZmEzNmZjYWFhZTZjY2ZjMzNlNzliOTk1MGE5MGNl
|
11
|
+
MjI0NjdiNDJiNjRjYzcxMjRhNGJmODUwNWIzMGYxZmQ1Yjg0ZDQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGUzMmU1N2Q5NzAyMjQ0NmQyOTE3NzQxYjNjMjY3ZDNhYjc4ZTNiZmQ0MmI0
|
14
|
+
MGQ2MWZmMzc4ODVmMzFhM2M1M2E1NWRmOTFmM2U3YTE2ZjQ2MGI1MjUwYWUw
|
15
|
+
MWY4ZWQ4NDQ4ZDIzM2UzMWUzNDlhMzQ1YzVlMmJmNjcyNjcwZTY=
|
@@ -77,7 +77,7 @@ six_or_seven_digit_mobile_prefixes = [
|
|
77
77
|
]
|
78
78
|
|
79
79
|
Phony.define do
|
80
|
-
country '855', one_of(six_digit_mobile_prefixes) >> matched_split(/^[1-9]/ => [3, 3]) |
|
80
|
+
country '855', trunk('0') | one_of(six_digit_mobile_prefixes) >> matched_split(/^[1-9]/ => [3, 3]) |
|
81
81
|
one_of(seven_digit_mobile_prefixes) >> matched_split(/^[2-9]/ => [3, 4]) |
|
82
82
|
one_of(six_or_seven_digit_mobile_prefixes) >> matched_split(
|
83
83
|
/^[2-9]\d{5}$/ => [3, 3], /^[1-9]\d{6}$/ => [3, 4]
|
@@ -1,9 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'Phony
|
3
|
+
describe 'Phony#normalize' do
|
4
4
|
|
5
5
|
describe 'cases' do
|
6
6
|
|
7
|
+
describe 'regressions' do
|
8
|
+
it '#151' do
|
9
|
+
# Normalizes, but this is a non-real case.
|
10
|
+
#
|
11
|
+
Phony.normalize('1-111-111-1111').should == '1111111111'
|
12
|
+
Phony.normalize('111-111-1111', cc: '1').should == '1111111111'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
7
16
|
it 'handles the US (with cc) correctly' do
|
8
17
|
Phony.normalize('+1 724 999 9999').should == '17249999999'
|
9
18
|
end
|
@@ -22,6 +31,89 @@ describe 'Phony.normalize' do
|
|
22
31
|
it 'handles a German number with extra 0' do
|
23
32
|
Phony.normalize('+49 0 209 22 33 44 55').should == '4920922334455'
|
24
33
|
end
|
34
|
+
|
35
|
+
it 'should normalize a too short number' do
|
36
|
+
Phony.normalize('+972').should eql '972'
|
37
|
+
end
|
38
|
+
it 'should normalize an already normalized number' do
|
39
|
+
Phony.normalize('41443643533').should eql '41443643533'
|
40
|
+
end
|
41
|
+
it 'should normalize a format number' do
|
42
|
+
Phony.normalize('+41 44 364 35 33').should eql '41443643533'
|
43
|
+
end
|
44
|
+
it 'should normalize a 00 number' do
|
45
|
+
Phony.normalize('0041 44 364 35 33').should eql '41443643533'
|
46
|
+
end
|
47
|
+
it 'should normalize a service number' do
|
48
|
+
Phony.normalize('+41 800 11 22 33').should eql '41800112233'
|
49
|
+
end
|
50
|
+
it 'should remove characters from the number' do
|
51
|
+
Phony.normalize('John: +41 44 364 35 33').should eql '41443643533'
|
52
|
+
end
|
53
|
+
it 'should normalize one of these crazy american numbers' do
|
54
|
+
Phony.normalize('1 (703) 451-5115').should eql '17034515115'
|
55
|
+
end
|
56
|
+
it 'should normalize another one of these crazy american numbers' do
|
57
|
+
Phony.normalize('1-888-407-4747').should eql '18884074747'
|
58
|
+
end
|
59
|
+
it 'should normalize a number with colons' do
|
60
|
+
Phony.normalize('1.906.387.1698').should eql '19063871698'
|
61
|
+
end
|
62
|
+
it 'should normalize a number with erroneous zero inside' do
|
63
|
+
Phony.normalize('+410443643533').should eql '41443643533'
|
64
|
+
end
|
65
|
+
it 'should not normalize a number with a correct zero inside' do
|
66
|
+
Phony.normalize('+390909709511').should eql '390909709511'
|
67
|
+
end
|
68
|
+
|
69
|
+
it "handles completely crazy 'numbers'" do
|
70
|
+
Phony.normalize('Hello, I am Cora, the 41th parrot, and 44 is my 364 times 35 funky number. 32.').should eql '41443643532'
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'special trunk prefixes are not handled' do
|
74
|
+
it 'normalizes Hungary' do
|
75
|
+
Phony.normalize('36 0630245506').should eql '360630245506'
|
76
|
+
end
|
77
|
+
it 'normalizes Russia' do
|
78
|
+
Phony.normalize('7 8 342 1234567').should eql '783421234567'
|
79
|
+
end
|
80
|
+
it 'normalizes Lithuania' do
|
81
|
+
Phony.normalize('370 8 5 1234567').should eql '370851234567'
|
82
|
+
end
|
83
|
+
it 'normalizes Belarus' do
|
84
|
+
Phony.normalize('375 152450911').should eql '375152450911'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'exceptions' do
|
89
|
+
it 'raises on nil' do
|
90
|
+
expect {
|
91
|
+
Phony.normalize nil
|
92
|
+
}.to raise_error(ArgumentError, 'Phone number cannot be nil. Use e.g. number && Phony.normalize(number).')
|
93
|
+
end
|
94
|
+
it 'raises if number starts with reserved zero code' do
|
95
|
+
expect do
|
96
|
+
Phony.normalize '+00 00 00 00 01'
|
97
|
+
end.to raise_error(Phony::NormalizationError, 'Phony could not normalize the given number. Is it a phone number?')
|
98
|
+
end
|
99
|
+
it 'raises a nice error message' do
|
100
|
+
expect do
|
101
|
+
Phony.normalize 'test'
|
102
|
+
end.to raise_error(Phony::NormalizationError, 'Phony could not normalize the given number. Is it a phone number?')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'country-based' do
|
107
|
+
it 'normalizes the US correctly' do
|
108
|
+
Phony["1"].normalize("555 1234567890").should eql '5551234567890'
|
109
|
+
Phony["1"].normalize("+1 555 1234567890").should eql '5551234567890'
|
110
|
+
Phony["1"].normalize("+1 (0) 555 1234567890").should eql '5551234567890'
|
111
|
+
end
|
112
|
+
it 'normalizes Japan correctly' do
|
113
|
+
Phony["81"].normalize("80 1234 5634").should eql '8012345634'
|
114
|
+
Phony["81"].normalize("Hello 80 1234 5634").should eql '8012345634'
|
115
|
+
end
|
116
|
+
end
|
25
117
|
end
|
26
118
|
|
27
119
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Phony::CountryCodes do
|
4
|
-
|
4
|
+
|
5
5
|
before(:all) do
|
6
6
|
@countries = Phony::CountryCodes.instance
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
describe 'international_absolute_format=' do
|
10
10
|
it 'formats correctly' do
|
11
11
|
@countries.formatted('41443643532', :format => :international).should eql '+41 44 364 35 32'
|
@@ -13,9 +13,9 @@ describe Phony::CountryCodes do
|
|
13
13
|
it 'formats correctly' do
|
14
14
|
old_format = @countries.international_absolute_format
|
15
15
|
@countries.international_absolute_format = '!!! %s%s%s'
|
16
|
-
|
16
|
+
|
17
17
|
@countries.formatted('41443643532', :format => :international).should eql '!!! 41 44 364 35 32'
|
18
|
-
|
18
|
+
|
19
19
|
@countries.international_absolute_format = old_format
|
20
20
|
end
|
21
21
|
end
|
@@ -26,9 +26,9 @@ describe Phony::CountryCodes do
|
|
26
26
|
it 'formats correctly' do
|
27
27
|
old_format = @countries.international_relative_format
|
28
28
|
@countries.international_relative_format = '000 %s%s%s'
|
29
|
-
|
29
|
+
|
30
30
|
@countries.formatted('41443643532', :format => :international_relative).should eql '000 41 44 364 35 32'
|
31
|
-
|
31
|
+
|
32
32
|
@countries.international_relative_format = old_format
|
33
33
|
end
|
34
34
|
end
|
@@ -39,21 +39,21 @@ describe Phony::CountryCodes do
|
|
39
39
|
it 'formats correctly' do
|
40
40
|
old_format = @countries.national_format
|
41
41
|
@countries.national_format = '%s%s'
|
42
|
-
|
42
|
+
|
43
43
|
# Removes CC 1, but adds national call prefix 1.
|
44
44
|
#
|
45
45
|
@countries.formatted('11231231234', :format => :national).should eql '1123 123 1234'
|
46
|
-
|
46
|
+
|
47
47
|
@countries.national_format = old_format
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
describe 'split' do
|
52
52
|
it 'splits correctly' do
|
53
53
|
@countries.split('41443643532').should eql ['41', '0', '44', '364', '35', '32']
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
describe 'formatted' do
|
58
58
|
it 'formats correctly' do
|
59
59
|
@countries.formatted('41443643532', :format => :international, :spaces => :-).should eql '+41-44-364-35-32'
|
@@ -74,6 +74,9 @@ describe Phony::CountryCodes do
|
|
74
74
|
it 'formats Spain correctly' do
|
75
75
|
@countries.formatted("34123456789", :format => :national).should eql '123 456 789'
|
76
76
|
end
|
77
|
+
it 'formats Cambodia correctly' do
|
78
|
+
@countries.formatted('85512239123', :format => :national).should eql '012 239 123'
|
79
|
+
end
|
77
80
|
end
|
78
81
|
context 'default' do
|
79
82
|
it "should format swiss numbers" do
|
@@ -187,5 +190,5 @@ describe Phony::CountryCodes do
|
|
187
190
|
end
|
188
191
|
end
|
189
192
|
end
|
190
|
-
|
193
|
+
|
191
194
|
end
|
data/spec/lib/phony_spec.rb
CHANGED
@@ -5,12 +5,6 @@ require 'spec_helper'
|
|
5
5
|
describe Phony do
|
6
6
|
|
7
7
|
describe 'regression' do
|
8
|
-
it '#151' do
|
9
|
-
# Normalizes, but this is a non-real case.
|
10
|
-
#
|
11
|
-
described_class.normalize('1-111-111-1111').should == '1111111111'
|
12
|
-
described_class.normalize('111-111-1111', cc: '1').should == '1111111111'
|
13
|
-
end
|
14
8
|
it 'best effort #152' do
|
15
9
|
described_class.split('39694805123').should == ['39', '694805123', []]
|
16
10
|
described_class.format('39694805123').should == '+39 694805123 '
|
@@ -27,87 +21,6 @@ describe Phony do
|
|
27
21
|
end
|
28
22
|
end
|
29
23
|
|
30
|
-
describe 'normalize' do
|
31
|
-
describe 'exceptions' do
|
32
|
-
it 'raises on nil' do
|
33
|
-
expect {
|
34
|
-
Phony.normalize nil
|
35
|
-
}.to raise_error(ArgumentError, 'Phone number cannot be nil. Use e.g. number && Phony.normalize(number).')
|
36
|
-
end
|
37
|
-
it 'raises if number starts with reserved zero code' do
|
38
|
-
expect do
|
39
|
-
Phony.normalize '+00 00 00 00 01'
|
40
|
-
end.to raise_error(Phony::NormalizationError, 'Phony could not normalize the given number. Is it a phone number?')
|
41
|
-
end
|
42
|
-
it 'raises a nice error message' do
|
43
|
-
expect do
|
44
|
-
Phony.normalize 'test'
|
45
|
-
end.to raise_error(Phony::NormalizationError, 'Phony could not normalize the given number. Is it a phone number?')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
describe 'some examples' do
|
49
|
-
it 'should normalize a too short number' do
|
50
|
-
Phony.normalize('+972').should eql '972'
|
51
|
-
end
|
52
|
-
it 'should normalize an already normalized number' do
|
53
|
-
Phony.normalize('41443643533').should eql '41443643533'
|
54
|
-
end
|
55
|
-
it 'should normalize a format number' do
|
56
|
-
Phony.normalize('+41 44 364 35 33').should eql '41443643533'
|
57
|
-
end
|
58
|
-
it 'should normalize a 00 number' do
|
59
|
-
Phony.normalize('0041 44 364 35 33').should eql '41443643533'
|
60
|
-
end
|
61
|
-
it 'should normalize a service number' do
|
62
|
-
Phony.normalize('+41 800 11 22 33').should eql '41800112233'
|
63
|
-
end
|
64
|
-
it 'should remove characters from the number' do
|
65
|
-
Phony.normalize('John: +41 44 364 35 33').should eql '41443643533'
|
66
|
-
end
|
67
|
-
it 'should normalize one of these crazy american numbers' do
|
68
|
-
Phony.normalize('1 (703) 451-5115').should eql '17034515115'
|
69
|
-
end
|
70
|
-
it 'should normalize another one of these crazy american numbers' do
|
71
|
-
Phony.normalize('1-888-407-4747').should eql '18884074747'
|
72
|
-
end
|
73
|
-
it 'should normalize a number with colons' do
|
74
|
-
Phony.normalize('1.906.387.1698').should eql '19063871698'
|
75
|
-
end
|
76
|
-
it 'should normalize a number with erroneous zero inside' do
|
77
|
-
Phony.normalize('+410443643533').should eql '41443643533'
|
78
|
-
end
|
79
|
-
it 'should not normalize a number with a correct zero inside' do
|
80
|
-
Phony.normalize('+390909709511').should eql '390909709511'
|
81
|
-
end
|
82
|
-
|
83
|
-
context 'special trunk prefixes are not handled' do
|
84
|
-
it 'normalizes Hungary' do
|
85
|
-
Phony.normalize('36 0630245506').should eql '360630245506'
|
86
|
-
end
|
87
|
-
it 'normalizes Russia' do
|
88
|
-
Phony.normalize('7 8 342 1234567').should eql '783421234567'
|
89
|
-
end
|
90
|
-
it 'normalizes Lithuania' do
|
91
|
-
Phony.normalize('370 8 5 1234567').should eql '370851234567'
|
92
|
-
end
|
93
|
-
it 'normalizes Belarus' do
|
94
|
-
Phony.normalize('375 152450911').should eql '375152450911'
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
describe 'country-based' do
|
99
|
-
it 'normalizes the US correctly' do
|
100
|
-
Phony["1"].normalize("555 1234567890").should eql '5551234567890'
|
101
|
-
Phony["1"].normalize("+1 555 1234567890").should eql '5551234567890'
|
102
|
-
Phony["1"].normalize("+1 (0) 555 1234567890").should eql '5551234567890'
|
103
|
-
end
|
104
|
-
it 'normalizes Japan correctly' do
|
105
|
-
Phony["81"].normalize("80 1234 5634").should eql '8012345634'
|
106
|
-
Phony["81"].normalize("Hello 80 1234 5634").should eql '8012345634'
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
24
|
describe 'formatted' do
|
112
25
|
it 'is an alias of format' do
|
113
26
|
Phony.formatted('41443643532').should eql '+41 44 364 35 32'
|
@@ -275,11 +188,6 @@ describe Phony do
|
|
275
188
|
end
|
276
189
|
|
277
190
|
context 'minimal cases' do
|
278
|
-
context 'normalizing' do
|
279
|
-
it "handles completely crazy 'numbers'" do
|
280
|
-
Phony.normalize('Hello, I am Cora, the 41th parrot, and 44 is my 364 times 35 funky number. 32.').should eql '41443643532'
|
281
|
-
end
|
282
|
-
end
|
283
191
|
context 'splitting' do
|
284
192
|
describe 'exceptions' do
|
285
193
|
it 'should raise on split nil' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Hanke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ! 'Fast international phone number (E164 standard) normalizing, splitting
|
14
14
|
and formatting. Lots of formatting options: International (+.., 00..), national
|