phony 1.6.0 → 1.6.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.
- data/lib/phony/country_codes.rb +2 -1
- data/lib/phony/national_code.rb +6 -6
- data/spec/lib/phony/countries_spec.rb +1 -0
- data/spec/lib/phony_spec.rb +10 -10
- metadata +3 -5
data/lib/phony/country_codes.rb
CHANGED
@@ -22,10 +22,11 @@ module Phony
|
|
22
22
|
@instance ||= new
|
23
23
|
end
|
24
24
|
|
25
|
+
@@normalizing_pattern = /^0+|\D/
|
25
26
|
def normalize number
|
26
27
|
# Remove non-digit chars.
|
27
28
|
#
|
28
|
-
number.gsub!
|
29
|
+
number.gsub! @@normalizing_pattern, EMPTY_STRING
|
29
30
|
national_handler, cc, rest = split_cc number
|
30
31
|
@normalize_format % [cc, national_handler.normalize(rest)]
|
31
32
|
end
|
data/lib/phony/national_code.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Phony
|
2
|
-
|
2
|
+
|
3
3
|
# NationalCodes have a special numbers splitter, a national code splitter and a local code splitter.
|
4
4
|
#
|
5
5
|
class NationalCode
|
6
|
-
|
6
|
+
|
7
7
|
#
|
8
8
|
#
|
9
9
|
def initialize national_splitter, local_splitter, normalize = nil
|
@@ -11,7 +11,7 @@ module Phony
|
|
11
11
|
@local_splitter = local_splitter
|
12
12
|
@normalize = normalize != false
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
# Split gets a number without country code and splits it into
|
16
16
|
# its parts.
|
17
17
|
#
|
@@ -20,7 +20,7 @@ module Phony
|
|
20
20
|
return ndc unless rest
|
21
21
|
[ndc, *@local_splitter.split(rest)]
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
# Split gets a number without country code and removes a relative zero.
|
25
25
|
#
|
26
26
|
# Note: Some cases, like Italy, don't remove the relative zero.
|
@@ -29,7 +29,7 @@ module Phony
|
|
29
29
|
return national_number unless @normalize
|
30
30
|
national_number.gsub(/^0+/, '')
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
end
|
@@ -86,6 +86,7 @@ describe 'country descriptions' do
|
|
86
86
|
end
|
87
87
|
it 'handles german numbers' do
|
88
88
|
Phony.split('493038625454').should == ['49', '30', '386', '25454'] # Berlin
|
89
|
+
Phony.split('4932221764542').should == ['49', '32', '221', '764542'] # Non-Geographical
|
89
90
|
Phony.split('4922137683323').should == ['49', '221', '376', '83323'] # Cologne
|
90
91
|
Phony.split('497614767676').should == ['49', '761', '476', '7676'] # Freiburg im Breisgau
|
91
92
|
Phony.split('4921535100').should == ['49', '2153', '510', '0'] # Nettetal-Lobberich
|
data/spec/lib/phony_spec.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Phony do
|
6
|
-
|
6
|
+
|
7
7
|
describe 'nil cases' do
|
8
8
|
it "should raise on normalize nil" do
|
9
9
|
expect {
|
@@ -21,7 +21,7 @@ describe Phony do
|
|
21
21
|
}.to raise_error(ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.split(number).")
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
describe "normalize" do
|
26
26
|
describe "some examples" do
|
27
27
|
it "should normalize an already normalized number" do
|
@@ -30,8 +30,8 @@ describe Phony do
|
|
30
30
|
it "should normalize a format number" do
|
31
31
|
Phony.normalize('+41 44 364 35 33').should == '41443643533'
|
32
32
|
end
|
33
|
-
it "should normalize a
|
34
|
-
Phony.normalize('
|
33
|
+
it "should normalize a 00 number" do
|
34
|
+
Phony.normalize('0041 44 364 35 33').should == '41443643533'
|
35
35
|
end
|
36
36
|
it "should normalize a service number" do
|
37
37
|
Phony.normalize('+41 800 11 22 33').should == '41800112233'
|
@@ -59,13 +59,13 @@ describe Phony do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
describe 'formatted' do
|
64
64
|
it 'is an alias of format' do
|
65
65
|
Phony.formatted('41443643532').should == '+41 44 364 35 32'
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
describe "format" do
|
70
70
|
describe "default" do
|
71
71
|
it "should format swiss numbers" do
|
@@ -182,7 +182,7 @@ describe Phony do
|
|
182
182
|
end
|
183
183
|
end
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
context 'minimal cases' do
|
187
187
|
context 'normalizing' do
|
188
188
|
it 'handles completely crazy "numbers"' do
|
@@ -217,7 +217,7 @@ describe Phony do
|
|
217
217
|
end
|
218
218
|
end
|
219
219
|
end
|
220
|
-
|
220
|
+
|
221
221
|
context "speed" do
|
222
222
|
before(:each) do
|
223
223
|
@phone_numbers = [
|
@@ -256,7 +256,7 @@ describe Phony do
|
|
256
256
|
end
|
257
257
|
end
|
258
258
|
end
|
259
|
-
|
259
|
+
|
260
260
|
describe 'vanity' do
|
261
261
|
describe 'vanity_number?' do
|
262
262
|
it {Phony.vanity?('41800 WEGGLI').should be_true}
|
@@ -266,7 +266,7 @@ describe Phony do
|
|
266
266
|
it {Phony.vanity?('41900 KURZ').should be_false}
|
267
267
|
it {Phony.vanity?('41 44 364 35 32').should be_false}
|
268
268
|
end
|
269
|
-
|
269
|
+
|
270
270
|
describe 'vanity_to_number' do
|
271
271
|
it {Phony.vanity_to_number('41800WEGGLI').should == '41800934454'}
|
272
272
|
it {Phony.vanity_to_number('41800weggli').should == '41800934454'}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-11-25 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
14
|
description: ! 'Fast international phone number (E164 standard) normalizing, splitting
|
16
15
|
and formatting. Lots of formatting options: International (+.., 00..), national
|
@@ -59,7 +58,6 @@ files:
|
|
59
58
|
- spec/lib/phony/national_splitters/variable_spec.rb
|
60
59
|
- spec/lib/phony/vanity_spec.rb
|
61
60
|
- spec/lib/phony_spec.rb
|
62
|
-
has_rdoc: true
|
63
61
|
homepage: http://github.com/floere/phony
|
64
62
|
licenses: []
|
65
63
|
post_install_message:
|
@@ -80,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
78
|
version: '0'
|
81
79
|
requirements: []
|
82
80
|
rubyforge_project:
|
83
|
-
rubygems_version: 1.
|
81
|
+
rubygems_version: 1.8.11
|
84
82
|
signing_key:
|
85
83
|
specification_version: 3
|
86
84
|
summary: Fast international phone number (E164 standard) normalizing, splitting and
|