phony 2.0.0 → 2.0.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 +8 -8
- data/lib/phony.rb +1 -0
- data/lib/phony/countries.rb +30 -26
- data/lib/phony/countries/italy.rb +5 -4
- data/lib/phony/countries/latvia.rb +5 -4
- data/lib/phony/countries/netherlands.rb +5 -4
- data/lib/phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb +8 -12
- data/lib/phony/countries/tajikistan.rb +7 -6
- data/lib/phony/countries/turkmenistan.rb +6 -5
- data/lib/phony/country_codes.rb +7 -2
- data/lib/phony/dsl.rb +4 -19
- data/lib/phony/local_splitters/fixed.rb +1 -1
- data/lib/phony/national_code.rb +2 -6
- data/lib/phony/national_splitters/dsl.rb +3 -3
- data/lib/phony/trunk_code.rb +35 -0
- data/spec/lib/phony/national_code_spec.rb +30 -30
- data/spec/lib/phony/validations_spec.rb +7 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGI2NWU3NWFlYjc4MmE5Y2EyYTdlYmFhYmM4Yzg2MjNmNWRkYzhlMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGI0NTI1ZTRjYzg1ZGU4OTc0NTA0ZmM5NmYzM2U4NzQ5ZTk4NjIxOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjllNWExZjBhNTk5YTNjMTM5NjYxMTJlZDNmNmM5MjAxNDE1NzgwNzEyNDFi
|
10
|
+
OGU2ZWZhMTY5MmYyY2Q5YTVkNmIzODc1YTViMDMyMzg0ZTcxZTJjZTVlYzc2
|
11
|
+
Zjk2NTQwOTNmNDJkZGExMzAyMTk4ODgyNzQxODM1ZjM2ZjM3ZDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTE5NzRjMzBlZWMwMzkxNDNmZTE0ZTQ5NDc4ZTdlMTI1ZDQwNzUxNTNkODNh
|
14
|
+
NjM0M2UxNWE4MmRhZGY4ZGZiMWFlNzEwNGVmOGI4OTIwMmZjZGI2NTcxNWNm
|
15
|
+
NDhmZjI2NTJmZDdlZTNjZGE5ODViOWM0MjczNjNhMGFiYzRhYjg=
|
data/lib/phony.rb
CHANGED
@@ -11,6 +11,7 @@ require File.expand_path '../phony/national_splitters/default', __FILE__
|
|
11
11
|
require File.expand_path '../phony/national_splitters/none', __FILE__
|
12
12
|
require File.expand_path '../phony/national_code', __FILE__
|
13
13
|
require File.expand_path '../phony/country', __FILE__
|
14
|
+
require File.expand_path '../phony/trunk_code', __FILE__
|
14
15
|
require File.expand_path '../phony/country_codes', __FILE__
|
15
16
|
|
16
17
|
require File.expand_path '../phony/dsl', __FILE__
|
data/lib/phony/countries.rb
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
# Note: The ones that are commented are defined in their special files.
|
21
21
|
#
|
22
22
|
Phony.define do
|
23
|
-
|
23
|
+
|
24
24
|
# Reserved.
|
25
25
|
#
|
26
26
|
country '0', fixed(1) >> split(10) # Reserved.
|
@@ -28,9 +28,9 @@ Phony.define do
|
|
28
28
|
# USA, Canada, etc.
|
29
29
|
#
|
30
30
|
country '1',
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
trunk('1') |
|
32
|
+
fixed(3, :zero => false) >> split(3,4),
|
33
|
+
:invalid_ndcs => ['911']
|
34
34
|
|
35
35
|
# Kazakhstan (Republic of) & Russsian Federation.
|
36
36
|
# also Abhasia and South Osetia autonomous regions / recognized by some states as independent countries
|
@@ -51,16 +51,17 @@ Phony.define do
|
|
51
51
|
# Greece. http://www.numberingplans.com/?page=dialling&sub=areacodes
|
52
52
|
# https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=GR
|
53
53
|
country '30',
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
54
|
+
trunk('0') |
|
55
|
+
one_of(%w(231 241 251 261 271 281)) >> split(3,4) |
|
56
|
+
one_of('800') >> split(3,4) | # freephone
|
57
|
+
one_of(%w(801 807)) >> split(3,4) | # shared cost, premium rate
|
58
|
+
one_of('896') >> split(3,4) | # ISP
|
59
|
+
one_of(%w(901 909)) >> split(3,4) | # premium rate
|
60
|
+
one_of(%w(21 22 23 24 25 26 27 28)) >> split(4,4) |
|
61
|
+
one_of('50') >> split(4,4) | # VPN
|
62
|
+
one_of('69') >> split(4,4) | # mobile, pager
|
63
|
+
one_of('70') >> split(4,4) | # universal access
|
64
|
+
fixed(4) >> split(6) # 3-digit NDCs
|
64
65
|
|
65
66
|
# country '31' # Netherlands, see special file.
|
66
67
|
|
@@ -83,9 +84,10 @@ Phony.define do
|
|
83
84
|
# Hungary.
|
84
85
|
#
|
85
86
|
country '36',
|
86
|
-
|
87
|
-
|
88
|
-
|
87
|
+
trunk('06') |
|
88
|
+
one_of('104','105','107','112') >> split(3,3) | # Service
|
89
|
+
one_of('1') >> split(3,4) | # Budapest
|
90
|
+
fixed(2) >> split(3,4) # 2-digit NDCs
|
89
91
|
|
90
92
|
# country '39' # Italy, see special file.
|
91
93
|
|
@@ -340,8 +342,8 @@ Phony.define do
|
|
340
342
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Rwanda
|
341
343
|
country '250',
|
342
344
|
one_of('25') >> split(7) | # Geographic, fixed
|
343
|
-
match(/^(7[238])/) >> split(7)
|
344
|
-
one_of('06') >> split(6)
|
345
|
+
match(/^(7[238])/) >> split(7) | # Non-geographic, mobile
|
346
|
+
one_of('06') >> split(6) # Satellite
|
345
347
|
|
346
348
|
country '251', fixed(2) >> split(3, 4) # Ethiopia http://www.wtng.info/wtng-251-et.html
|
347
349
|
|
@@ -352,8 +354,9 @@ Phony.define do
|
|
352
354
|
# Kenya
|
353
355
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Kenya
|
354
356
|
country '254',
|
355
|
-
|
356
|
-
|
357
|
+
trunk('0') |
|
358
|
+
match(/^(7\d\d)/) >> split(6) | # mobile
|
359
|
+
fixed(2) >> split(7) # landline
|
357
360
|
|
358
361
|
# Tanzania.
|
359
362
|
#
|
@@ -562,11 +565,12 @@ Phony.define do
|
|
562
565
|
# Lithuania
|
563
566
|
#
|
564
567
|
country '370',
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
568
|
+
trunk('8') |
|
569
|
+
one_of('700', '800') >> split(2,3) | # Service
|
570
|
+
match(/^(6\d\d)\d+$/) >> split(2,3) | # Mobile
|
571
|
+
one_of('5') >> split(3,2,2) | # Vilnius
|
572
|
+
one_of('37','41') >> split(2,2,2) | # Kaunas, Šiauliai
|
573
|
+
fixed(3) >> split(1,2,2) # 3-digit NDCs.
|
570
574
|
|
571
575
|
# country '371' # Latvia, see special file
|
572
576
|
|
@@ -152,8 +152,9 @@ service = [ # Not exhaustive.
|
|
152
152
|
]
|
153
153
|
|
154
154
|
Phony.define do
|
155
|
-
country '39',
|
156
|
-
one_of(*
|
157
|
-
one_of(*
|
158
|
-
one_of(*
|
155
|
+
country '39', trunk('0', :normalize => false) |
|
156
|
+
one_of(*service) >> split(3,3) |
|
157
|
+
one_of(*mobile) >> split(3,4) |
|
158
|
+
one_of(*ndcs_2digit) >> split(4,4) |
|
159
|
+
one_of(*ndcs, :max_length => 3) >> split(3,4)
|
159
160
|
end
|
@@ -33,8 +33,9 @@ ndcs_with_5_subscriber_numbers = %w(
|
|
33
33
|
ndcs_with_6_subscriber_numbers = %w(67)
|
34
34
|
|
35
35
|
Phony.define do
|
36
|
-
country '371',
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
country '371',
|
37
|
+
trunk('8', :normalize => false) |
|
38
|
+
one_of(ndcs_with_5_subscriber_numbers) >> split(3,2) |
|
39
|
+
one_of(ndcs_with_6_subscriber_numbers) >> split(3,3) |
|
40
|
+
fixed(3) >> split(3,2)
|
40
41
|
end
|
@@ -51,8 +51,9 @@ service = [
|
|
51
51
|
]
|
52
52
|
|
53
53
|
Phony.define do
|
54
|
-
country '31',
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
country '31',
|
55
|
+
one_of(service) >> split(3,3) |
|
56
|
+
one_of('6') >> split(2,2,2,2) | # mobile
|
57
|
+
one_of(ndcs) >> split(3,4) | # landline (geographic region)
|
58
|
+
fixed(3) >> split(3,3) # 3 digit ndc
|
58
59
|
end
|
@@ -117,16 +117,12 @@ ndcs_with_7_subscriber_digits = %w(342 343 347 351 383 391 473 495 496 498 499 8
|
|
117
117
|
)
|
118
118
|
|
119
119
|
Phony.define do
|
120
|
-
country '7',
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
# match(/([67]\d{2})/) >> split(2, 2, 2) | # Kazakhstan: (600..799)
|
129
|
-
# one_of(%w(840 940)) >> split(2,2,2) # Abhasia
|
130
|
-
|
131
|
-
fixed(3) >> trunk('8') >> split(2,2,3) # TODO 2,2,3 or 2,2,2?
|
120
|
+
country '7',
|
121
|
+
trunk('8') |
|
122
|
+
one_of(ndcs_with_5_subscriber_digits) >> split(1, 2, 2) |
|
123
|
+
one_of(ndcs_with_6_subscriber_digits) >> split(2, 2, 2) |
|
124
|
+
one_of(ndcs_with_7_subscriber_digits) >> split(3, 2, 2) |
|
125
|
+
one_of(%w(800)) >> split(3, 2, 2) | # Russia free number
|
126
|
+
one_of(%w(995344 9971 99744 9976 997)) >> split(2, 2, 2) | # South Osetia
|
127
|
+
fixed(3) >> split(2, 2, 3)
|
132
128
|
end
|
@@ -67,10 +67,11 @@ ndcs_with_3_subscriber_digits = %w(331700)
|
|
67
67
|
|
68
68
|
Phony.define do
|
69
69
|
country '992',
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
70
|
+
trunk('8') |
|
71
|
+
one_of(ndcs_with_3_subscriber_digits) >> split(3) |
|
72
|
+
one_of(ndcs_with_5_subscriber_digits) >> split(3,2) |
|
73
|
+
one_of(ndcs_with_6_subscriber_digits) >> split(3,3) |
|
74
|
+
match(/\A(505|9\d\d)\d+\z/) >> split(3,3) | # mobile
|
75
|
+
one_of(%w(446 474 487)) >> split(3,3) | # wireless geographic
|
76
|
+
fixed(3) >> split(3,3)
|
76
77
|
end
|
@@ -65,9 +65,10 @@ ndcs_with_4_subscriber_digits = %w(1392)
|
|
65
65
|
|
66
66
|
Phony.define do
|
67
67
|
country '993',
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
trunk('8') |
|
69
|
+
one_of(ndcs_with_4_subscriber_digits) >> split(4) |
|
70
|
+
one_of(ndcs_with_5_subscriber_digits) >> split(3,2) |
|
71
|
+
one_of(ndcs_with_6_subscriber_digits) >> split(3,3) |
|
72
|
+
one_of('6') >> split(3,4) | # mobile
|
73
|
+
fixed(3) >> split(3,2)
|
73
74
|
end
|
data/lib/phony/country_codes.rb
CHANGED
@@ -34,14 +34,19 @@ module Phony
|
|
34
34
|
# We can't know from what country that person was calling, so we
|
35
35
|
# can't remove the intl' call prefix.
|
36
36
|
#
|
37
|
-
|
37
|
+
# We remove:
|
38
|
+
# * 0 or 00 at the very beginning.
|
39
|
+
# * (0) anywhere.
|
40
|
+
# * Non-digits.
|
41
|
+
#
|
42
|
+
@@basic_cleaning_pattern = /^00?|\(0\)|\D/
|
38
43
|
def clean number
|
39
44
|
clean! number && number.dup
|
40
45
|
end
|
41
46
|
def clean! number
|
42
47
|
# Remove non-digit chars.
|
43
48
|
#
|
44
|
-
number.gsub!(@@
|
49
|
+
number.gsub!(@@basic_cleaning_pattern, EMPTY_STRING) || number
|
45
50
|
end
|
46
51
|
def normalize number, options = {}
|
47
52
|
clean! number
|
data/lib/phony/dsl.rb
CHANGED
@@ -54,25 +54,10 @@ module Phony
|
|
54
54
|
Phony::CountryCodes.instance.add country_code, definition
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
def initialize code, options = {}
|
60
|
-
@code = code
|
61
|
-
@normalize = options[:normalize]
|
62
|
-
end
|
63
|
-
|
64
|
-
def national_splitter= national_splitter
|
65
|
-
@national_splitter = national_splitter
|
66
|
-
end
|
67
|
-
|
68
|
-
def >> local_splitter
|
69
|
-
@national_splitter.country_for local_splitter, @normalize, @code
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
57
|
+
#
|
58
|
+
#
|
74
59
|
def trunk code, options = {}
|
75
|
-
|
60
|
+
TrunkCode.new code, options
|
76
61
|
end
|
77
62
|
|
78
63
|
# National matcher & splitters.
|
@@ -150,7 +135,7 @@ module Phony
|
|
150
135
|
# This country still uses a default NDC (and needs to be done, hence the todo).
|
151
136
|
#
|
152
137
|
def todo
|
153
|
-
none >>
|
138
|
+
none >> split(10)
|
154
139
|
end
|
155
140
|
|
156
141
|
# Local splitters.
|
data/lib/phony/national_code.rb
CHANGED
@@ -8,12 +8,9 @@ module Phony
|
|
8
8
|
|
9
9
|
#
|
10
10
|
#
|
11
|
-
def initialize national_splitter, local_splitter
|
11
|
+
def initialize national_splitter, local_splitter
|
12
12
|
@national_splitter = national_splitter
|
13
13
|
@local_splitter = local_splitter
|
14
|
-
@normalize = normalize != false
|
15
|
-
@trunk_code = trunk_code
|
16
|
-
@trunk_code_replacement = /\A#{@trunk_code}+/
|
17
14
|
end
|
18
15
|
|
19
16
|
# Split gets a number without country code and splits it into
|
@@ -30,8 +27,7 @@ module Phony
|
|
30
27
|
# Note: Some cases, like Italy, don't remove the relative zero.
|
31
28
|
#
|
32
29
|
def normalize national_number
|
33
|
-
|
34
|
-
national_number.gsub(@trunk_code_replacement, EMPTY_STRING)
|
30
|
+
national_number.gsub(/\A0+/, EMPTY_STRING)
|
35
31
|
end
|
36
32
|
|
37
33
|
end
|
@@ -10,15 +10,15 @@ module Phony
|
|
10
10
|
#
|
11
11
|
def >> local_splitter
|
12
12
|
if local_splitter.respond_to? :split
|
13
|
-
country_for local_splitter
|
13
|
+
country_for local_splitter
|
14
14
|
else
|
15
15
|
local_splitter.national_splitter = self
|
16
16
|
local_splitter
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def country_for local_splitter
|
21
|
-
Phony::Country.new Phony::NationalCode.new(self, local_splitter
|
20
|
+
def country_for local_splitter
|
21
|
+
Phony::Country.new Phony::NationalCode.new(self, local_splitter)
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Phony
|
2
|
+
|
3
|
+
class TrunkCode
|
4
|
+
|
5
|
+
def initialize code, options = {}
|
6
|
+
@trunk_code_replacement = /\A#{code}+/
|
7
|
+
@normalize = options[:normalize] != false
|
8
|
+
@split = options[:split]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Prepends itself to the other codes.
|
12
|
+
#
|
13
|
+
def | other
|
14
|
+
other.codes.unshift self
|
15
|
+
other
|
16
|
+
end
|
17
|
+
|
18
|
+
# Split gets a number without country code and splits it into
|
19
|
+
# its parts.
|
20
|
+
#
|
21
|
+
def split national_number
|
22
|
+
national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @split
|
23
|
+
return [@code, national_number]
|
24
|
+
end
|
25
|
+
|
26
|
+
# Never normalizes.
|
27
|
+
#
|
28
|
+
def normalize national_number
|
29
|
+
return national_number unless @normalize
|
30
|
+
national_number.gsub @trunk_code_replacement, EMPTY_STRING
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -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
|
@@ -440,6 +440,13 @@ describe 'validations' do
|
|
440
440
|
#'+850 2 8801 1234 5678 1256',
|
441
441
|
'+850 191 123 4567']
|
442
442
|
it_is_correct_for 'Kuwait (State of)', :samples => ['+965 2345 6789', '+965 181 2345' ]
|
443
|
+
it_is_correct_for 'Kenya', :samples => [
|
444
|
+
'254201234567',
|
445
|
+
'254111234567',
|
446
|
+
'254723100220',
|
447
|
+
'+254-20-4262 140',
|
448
|
+
'+254-(0)20-4262 140'
|
449
|
+
]
|
443
450
|
it_is_correct_for 'Kyrgyzstan', :samples => ['+996 312 212 345',
|
444
451
|
'+996 315 212 345',
|
445
452
|
'+996 3131 212 34',
|
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.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Hanke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-15 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
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/phony/national_splitters/none.rb
|
68
68
|
- lib/phony/national_splitters/regex.rb
|
69
69
|
- lib/phony/national_splitters/variable.rb
|
70
|
+
- lib/phony/trunk_code.rb
|
70
71
|
- lib/phony/vanity.rb
|
71
72
|
- lib/phony.rb
|
72
73
|
- README.textile
|