phony 1.2.8 → 1.2.9
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/countries/all_other.rb +3 -2
- data/lib/phony/countries/belgium.rb +1 -0
- data/lib/phony/countries/hungary.rb +1 -1
- data/lib/phony/countries/peru.rb +1 -1
- data/lib/phony/countries/portugal.rb +1 -0
- data/lib/phony/countries/romania.rb +1 -0
- data/lib/phony/country.rb +19 -7
- data/spec/lib/phony/country_spec.rb +2 -1
- metadata +2 -2
@@ -74,8 +74,9 @@ module Phony
|
|
74
74
|
'43' => Countries::Austria,
|
75
75
|
'44' => fixed(2), # TODO United Kingdom of Great Britain and Northern Ireland
|
76
76
|
'45' => fixed(2, # Denmark
|
77
|
-
:local_format => [2, 2, 2]
|
78
|
-
|
77
|
+
:local_format => [2, 2, 2],
|
78
|
+
:service_ndcs => %w{112 114}
|
79
|
+
), # Denmark has no NDC, but 4 groups of 2 digits. I'm faking it here.
|
79
80
|
'46' => Countries::Sweden,
|
80
81
|
'47' => fixed(4, # Norway
|
81
82
|
:local_format => [4]
|
data/lib/phony/countries/peru.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Peru
|
4
4
|
#
|
5
5
|
Phony::Countries::Peru = Phony::Country.configured :local_format => [4, 4],
|
6
|
-
:
|
6
|
+
:service_local_format => [3, 3],
|
7
7
|
:ndc_fallback_length => 2,
|
8
8
|
:ndc_mapping => {
|
9
9
|
:landline => [
|
data/lib/phony/country.rb
CHANGED
@@ -4,16 +4,20 @@ module Phony
|
|
4
4
|
#
|
5
5
|
class Country
|
6
6
|
|
7
|
-
def initialize national_code, special_code = nil
|
7
|
+
def initialize national_code, special_code = nil, mobile_code = nil
|
8
8
|
@national_code = national_code
|
9
9
|
@special_code = special_code
|
10
|
+
@mobile_code = mobile_code
|
10
11
|
end
|
11
12
|
|
12
13
|
#
|
13
14
|
#
|
14
15
|
def split national_number
|
15
16
|
ndc, *rest = @special_code.split national_number if @special_code
|
16
|
-
ndc, *rest
|
17
|
+
return [ndc, *rest] if rest && !rest.empty?
|
18
|
+
ndc, *rest = @mobile_code.split national_number if @mobile_code
|
19
|
+
return [ndc, *rest] if rest && !rest.empty?
|
20
|
+
ndc, *rest = @national_code.split national_number
|
17
21
|
[ndc, *rest]
|
18
22
|
end
|
19
23
|
|
@@ -27,8 +31,10 @@ module Phony
|
|
27
31
|
#
|
28
32
|
def normalize national_number
|
29
33
|
normalized = @special_code.normalize national_number if @special_code
|
30
|
-
normalized
|
31
|
-
normalized
|
34
|
+
return normalized if normalized && !normalized.empty?
|
35
|
+
normalized = @mobile_code.normalize national_number if @mobile_code
|
36
|
+
return normalized if normalized && !normalized.empty?
|
37
|
+
@national_code.normalize national_number
|
32
38
|
end
|
33
39
|
|
34
40
|
# Is this national number a vanity number?
|
@@ -77,8 +83,14 @@ module Phony
|
|
77
83
|
service_local_splitter = Phony::LocalSplitter.instance_for options[:service_local_format] || [3, 6]
|
78
84
|
service_code = Phony::NationalCode.new service_national_splitter, service_local_splitter, normalize
|
79
85
|
end
|
86
|
+
if ndc_mapping[:mobile]
|
87
|
+
mobile_local_format = options[:mobile_local_format] || options[:local_format] || [9]
|
88
|
+
mobile_national_splitter = Phony::NationalSplitters::Variable.new nil, :mobile => ndc_mapping[:mobile]
|
89
|
+
mobile_local_splitter = Phony::LocalSplitter.instance_for mobile_local_format
|
90
|
+
mobile_code = Phony::NationalCode.new mobile_national_splitter, mobile_local_splitter, normalize
|
91
|
+
end
|
80
92
|
|
81
|
-
new national_code, service_code
|
93
|
+
new national_code, service_code, mobile_code
|
82
94
|
end
|
83
95
|
|
84
96
|
# Gets a configured country instance with fixed length ndc code.
|
@@ -104,9 +116,9 @@ module Phony
|
|
104
116
|
|
105
117
|
service_code = nil
|
106
118
|
if service_ndcs
|
107
|
-
service_local_format = options[:service_local_format] || local_format
|
119
|
+
service_local_format = options[:service_local_format] || local_format || [3, 3]
|
108
120
|
service_national_splitter = Phony::NationalSplitters::Variable.new nil, :service => service_ndcs
|
109
|
-
service_local_splitter = Phony::LocalSplitter.instance_for service_local_format
|
121
|
+
service_local_splitter = Phony::LocalSplitter.instance_for service_local_format
|
110
122
|
service_code = Phony::NationalCode.new service_national_splitter, service_local_splitter, normalize
|
111
123
|
end
|
112
124
|
|
@@ -7,6 +7,7 @@ describe Phony::Country do
|
|
7
7
|
before(:each) do
|
8
8
|
@country = Phony::Country.configured :local_format => [3, 2, 2],
|
9
9
|
:service_local_format => [3, 3],
|
10
|
+
:mobile_local_format => [1, 2, 4],
|
10
11
|
:ndc_fallback_length => 4,
|
11
12
|
:ndc_mapping => {
|
12
13
|
:normal => ['44'],
|
@@ -21,7 +22,7 @@ describe Phony::Country do
|
|
21
22
|
@country.split('800333666').should == ['800', '333', '666']
|
22
23
|
end
|
23
24
|
it 'works with mobile numbers' do
|
24
|
-
@country.split('764333532').should == ['76', '
|
25
|
+
@country.split('764333532').should == ['76', '4', '33', '3532']
|
25
26
|
end
|
26
27
|
it 'uses the fallback if it is not in the mapping' do
|
27
28
|
@country.split('123456789').should == ['1234', '567', '89']
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: phony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.2.
|
5
|
+
version: 1.2.9
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Florian Hanke
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-03 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|