phony 2.1.0 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +9 -9
- data/lib/phony/countries.rb +4 -4
- data/lib/phony/country.rb +8 -6
- data/lib/phony/country_codes.rb +5 -3
- data/spec/functional/plausibility_spec.rb +6 -0
- data/spec/lib/phony/countries_spec.rb +6 -6
- data/spec/lib/phony_spec.rb +14 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTI2YjZiNDBhODQ4NWQ1NTIzNmNlODllOTY3N2UyZTRhM2MxNmM1MQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
M2UwYmM0ZmNjMjMwNWE1YTE5ZTY5YjNiOWY4ZjU4ZGI4ZDM4Y2Q5Mw==
|
7
|
+
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjM2MzVlMGU3ODM4NmFmMmM0MGFjZjc5ZTk2Y2UxMmI0NjBjNDQzN2E3MWVh
|
10
|
+
ZmU1Y2NjMDE1ZTU2YWY3ZGM4MzI5ZDJlMjY0YTBhYjUwNDk4NDQ3Zjc4Zjcz
|
11
|
+
NDE4NmQ2MGJhYzk3N2RlNDEzNzUwYmNlOGRiYjE4Y2JiNGUxODA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjM0NjU1MDNkYjA2YTU2MjBmYTU4ZmM4ZTMxYmUxNTNiNjgwOGViYjE2ODM3
|
14
|
+
MjNlZmJiZTE4YTk3ZTkwNjUwYjYzOThkODRkM2E3ZjNjMDVhZTkwYzg0Zjkx
|
15
|
+
YzJlZmU0ZDRjOGQzNzVlNDMyZTY1NmM3NTI0OTU5NWQ1N2YwOWM=
|
data/lib/phony/countries.rb
CHANGED
@@ -67,10 +67,10 @@ Phony.define do
|
|
67
67
|
|
68
68
|
# Belgium.
|
69
69
|
#
|
70
|
-
country '32', match(/^(70|800|90\d)\d+$/) >> split(3,3)
|
71
|
-
match(/^(4[789]\d)\d{6}$/) >> split(6)
|
72
|
-
one_of('2','3','4','9') >> split(3,
|
73
|
-
fixed(2) >> split(
|
70
|
+
country '32', match(/^(70|800|90\d)\d+$/) >> split(3,3) | # Service
|
71
|
+
match(/^(4[789]\d)\d{6}$/) >> split(6) | # Mobile
|
72
|
+
one_of('2','3','4','9') >> split(3,2,2) | # Short NDCs
|
73
|
+
fixed(2) >> split(2,2,2) # 2-digit NDCs
|
74
74
|
|
75
75
|
# France.
|
76
76
|
#
|
data/lib/phony/country.rb
CHANGED
@@ -45,15 +45,17 @@ module Phony
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
#
|
48
|
+
# Cleans all non-numeric characters.
|
49
|
+
#
|
50
|
+
@@basic_cleaning_pattern = /\(0\)|\D/
|
51
|
+
# Clean number of all non-numeric characters and return a copy.
|
49
52
|
#
|
50
|
-
@@basic_cleaning_pattern = /\D/
|
51
53
|
def clean number
|
52
54
|
clean! number && number.dup
|
53
55
|
end
|
56
|
+
# Clean number of all non-numeric characters and return it.
|
57
|
+
#
|
54
58
|
def clean! number
|
55
|
-
# Remove non-digit chars.
|
56
|
-
#
|
57
59
|
number.gsub!(@@basic_cleaning_pattern, EMPTY_STRING) || number
|
58
60
|
end
|
59
61
|
|
@@ -66,7 +68,7 @@ module Phony
|
|
66
68
|
countrify! number || number
|
67
69
|
end
|
68
70
|
def countrify! number
|
69
|
-
number.sub! /\A(?!#{@cc})
|
71
|
+
number.sub! /\A(?!#{@cc})/, @cc
|
70
72
|
end
|
71
73
|
|
72
74
|
# Removes 0s from partially normalized numbers
|
@@ -79,7 +81,7 @@ module Phony
|
|
79
81
|
#
|
80
82
|
def normalize national_number
|
81
83
|
clean! national_number
|
82
|
-
normalized = @codes.reduce
|
84
|
+
normalized = @codes.reduce national_number do |number, code|
|
83
85
|
result = code.normalize number
|
84
86
|
break result if result
|
85
87
|
number
|
data/lib/phony/country_codes.rb
CHANGED
@@ -27,15 +27,17 @@ module Phony
|
|
27
27
|
countries[cc.size][cc]
|
28
28
|
end
|
29
29
|
|
30
|
-
#
|
30
|
+
# Clean number of all non-numeric characters, initial zeros or (0).
|
31
31
|
#
|
32
32
|
@@basic_cleaning_pattern = /\A00?|\(0\)|\D/
|
33
|
+
# Clean number of all non-numeric characters, initial zeros or (0) and return it.
|
34
|
+
#
|
33
35
|
def clean number
|
34
36
|
clean! number && number.dup
|
35
37
|
end
|
38
|
+
# Clean number of all non-numeric characters, initial zeros or (0) and return a copy.
|
39
|
+
#
|
36
40
|
def clean! number
|
37
|
-
# Remove non-digit chars.
|
38
|
-
#
|
39
41
|
number.gsub!(@@basic_cleaning_pattern, EMPTY_STRING) || number
|
40
42
|
end
|
41
43
|
|
@@ -122,6 +122,12 @@ describe 'plausibility' do
|
|
122
122
|
Phony.plausible?('+41 44 111 22 334').should be_false
|
123
123
|
Phony.plausible?('+41 44 111 22').should be_false
|
124
124
|
end
|
125
|
+
|
126
|
+
it "is correct for Belgian numbers" do
|
127
|
+
Phony.plausible?('+32 3 241 11 32').should be_true
|
128
|
+
Phony.plausible?('0032 3 241 11 32').should be_true
|
129
|
+
Phony.plausible?('0032 (0) 3 241 11 32').should be_true
|
130
|
+
end
|
125
131
|
|
126
132
|
it "is correct for Danish numbers" do
|
127
133
|
Phony.plausible?('+45 44 11 12 23 34').should be_false
|
@@ -70,12 +70,12 @@ describe 'country descriptions' do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
describe 'Belgium' do
|
73
|
-
it_splits '3235551212', ['32', '3', '555', '
|
74
|
-
it_splits '
|
75
|
-
it_splits '3225551212', ['32', '2', '555', '
|
76
|
-
it_splits '3295551914', ['32', '9', '555', '
|
77
|
-
it_splits '3245551414', ['32', '4', '555', '
|
78
|
-
it_splits '3216473200', ['32', '16', '
|
73
|
+
it_splits '3235551212', ['32', '3', '555', '12', '12'] # Antwerpen
|
74
|
+
it_splits '3250551212', ['32', '50', '55', '12', '12'] # Brugge
|
75
|
+
it_splits '3225551212', ['32', '2', '555', '12', '12'] # Brussels
|
76
|
+
it_splits '3295551914', ['32', '9', '555', '19', '14'] # Gent
|
77
|
+
it_splits '3245551414', ['32', '4', '555', '14', '14'] # Liège
|
78
|
+
it_splits '3216473200', ['32', '16', '47', '32', '00'] # Leuven
|
79
79
|
it_splits '32475279584', ['32', '475', '279584'] # mobile
|
80
80
|
it_splits '3270123123', ['32', '70', '123', '123'] # Bus Service?
|
81
81
|
end
|
data/spec/lib/phony_spec.rb
CHANGED
@@ -75,9 +75,21 @@ describe Phony do
|
|
75
75
|
it 'normalizes Lithuania' do
|
76
76
|
Phony.normalize('370 8 5 1234567').should == '37051234567'
|
77
77
|
end
|
78
|
-
it 'normalizes Belarus'
|
78
|
+
it 'normalizes Belarus' do
|
79
|
+
Phony.normalize('375 152450911').should == '375152450911'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
describe 'country-based' do
|
84
|
+
it 'normalizes the US correctly' do
|
85
|
+
Phony["1"].normalize("555 1234567890").should == '15551234567890'
|
86
|
+
Phony["1"].normalize("+1 555 1234567890").should == '15551234567890'
|
87
|
+
Phony["1"].normalize("+1 (0) 555 1234567890").should == '15551234567890'
|
88
|
+
end
|
89
|
+
it 'normalizes Japan correctly' do
|
90
|
+
Phony["81"].normalize("80 1234 5634").should == '818012345634'
|
91
|
+
Phony["81"].normalize("+81 80 1234 5634").should == '818012345634'
|
79
92
|
end
|
80
|
-
|
81
93
|
end
|
82
94
|
end
|
83
95
|
|
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.1.
|
4
|
+
version: 2.1.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-01-
|
11
|
+
date: 2014-01-09 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
|
@@ -19,9 +19,6 @@ extensions: []
|
|
19
19
|
extra_rdoc_files:
|
20
20
|
- README.textile
|
21
21
|
files:
|
22
|
-
- README.textile
|
23
|
-
- lib/phony.rb
|
24
|
-
- lib/phony/countries.rb
|
25
22
|
- lib/phony/countries/austria.rb
|
26
23
|
- lib/phony/countries/bangladesh.rb
|
27
24
|
- lib/phony/countries/belarus.rb
|
@@ -58,6 +55,7 @@ files:
|
|
58
55
|
- lib/phony/countries/united_kingdom.rb
|
59
56
|
- lib/phony/countries/uruguay.rb
|
60
57
|
- lib/phony/countries/zimbabwe.rb
|
58
|
+
- lib/phony/countries.rb
|
61
59
|
- lib/phony/country.rb
|
62
60
|
- lib/phony/country_codes.rb
|
63
61
|
- lib/phony/dsl.rb
|
@@ -72,6 +70,8 @@ files:
|
|
72
70
|
- lib/phony/national_splitters/variable.rb
|
73
71
|
- lib/phony/trunk_code.rb
|
74
72
|
- lib/phony/vanity.rb
|
73
|
+
- lib/phony.rb
|
74
|
+
- README.textile
|
75
75
|
- spec/functional/normalize_spec.rb
|
76
76
|
- spec/functional/plausibility_spec.rb
|
77
77
|
- spec/lib/phony/countries_spec.rb
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.0.3
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: Fast international phone number (E164 standard) normalizing, splitting and
|