phony 1.9.0 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +1 -1
- data/lib/phony.rb +28 -15
- data/lib/phony/countries.rb +609 -210
- data/lib/phony/countries/austria.rb +6 -1
- data/lib/phony/countries/bangladesh.rb +55 -0
- data/lib/phony/countries/belarus.rb +130 -0
- data/lib/phony/countries/georgia.rb +91 -0
- data/lib/phony/countries/germany.rb +20 -6
- data/lib/phony/countries/india.rb +50 -0
- data/lib/phony/countries/indonesia.rb +50 -0
- data/lib/phony/countries/italy.rb +38 -67
- data/lib/phony/countries/japan.rb +412 -0
- data/lib/phony/countries/kyrgyzstan.rb +118 -0
- data/lib/phony/countries/latvia.rb +40 -0
- data/lib/phony/countries/libya.rb +114 -0
- data/lib/phony/countries/malaysia.rb +7 -5
- data/lib/phony/countries/moldova.rb +50 -0
- data/lib/phony/countries/montenegro.rb +27 -0
- data/lib/phony/countries/namibia.rb +35 -0
- data/lib/phony/countries/nepal.rb +71 -0
- data/lib/phony/countries/netherlands.rb +3 -2
- data/lib/phony/countries/pakistan.rb +119 -0
- data/lib/phony/countries/paraguay.rb +145 -0
- data/lib/phony/countries/russia_kazakhstan_abhasia_south_osetia.rb +6 -6
- data/lib/phony/countries/serbia.rb +34 -0
- data/lib/phony/countries/somali.rb +22 -0
- data/lib/phony/countries/south_korea.rb +1 -1
- data/lib/phony/countries/sweden.rb +1 -1
- data/lib/phony/countries/taiwan.rb +51 -0
- data/lib/phony/countries/tajikistan.rb +76 -0
- data/lib/phony/countries/turkmenistan.rb +73 -0
- data/lib/phony/countries/ukraine.rb +614 -0
- data/lib/phony/countries/uruguay.rb +51 -0
- data/lib/phony/countries/zimbabwe.rb +37 -0
- data/lib/phony/country.rb +41 -0
- data/lib/phony/country_codes.rb +45 -18
- data/lib/phony/dsl.rb +33 -7
- data/lib/phony/local_splitters/fixed.rb +14 -1
- data/lib/phony/local_splitters/regex.rb +12 -1
- data/lib/phony/national_code.rb +7 -3
- data/lib/phony/national_splitters/default.rb +13 -1
- data/lib/phony/national_splitters/dsl.rb +9 -7
- data/lib/phony/national_splitters/fixed.rb +6 -0
- data/lib/phony/national_splitters/none.rb +6 -0
- data/lib/phony/national_splitters/regex.rb +6 -0
- data/lib/phony/national_splitters/variable.rb +7 -1
- data/spec/lib/phony/countries_spec.rb +684 -16
- data/spec/lib/phony/local_splitters/regex_spec.rb +41 -0
- data/spec/lib/phony/validations_spec.rb +542 -10
- data/spec/lib/phony_spec.rb +20 -6
- metadata +29 -9
- data/lib/phony/validator.rb +0 -26
- data/lib/phony/validators.rb +0 -88
data/spec/lib/phony_spec.rb
CHANGED
@@ -60,6 +60,20 @@ describe Phony do
|
|
60
60
|
it "should not normalize a number with a correct zero inside" do
|
61
61
|
Phony.normalize('+390909709511').should == '390909709511'
|
62
62
|
end
|
63
|
+
|
64
|
+
context 'special trunk prefixes' do
|
65
|
+
it 'normalizes Hungary' do
|
66
|
+
Phony.normalize('36 0630245506').should == '3630245506'
|
67
|
+
end
|
68
|
+
it 'normalizes Russia' do
|
69
|
+
Phony.normalize('7 8 342 1234567').should == '73421234567'
|
70
|
+
end
|
71
|
+
it 'normalizes Lithuania' do
|
72
|
+
Phony.normalize('370 8 5 1234567').should == '37051234567'
|
73
|
+
end
|
74
|
+
it 'normalizes Belarus'
|
75
|
+
end
|
76
|
+
|
63
77
|
end
|
64
78
|
end
|
65
79
|
|
@@ -150,16 +164,16 @@ describe Phony do
|
|
150
164
|
end
|
151
165
|
describe '"unsupported" countries' do
|
152
166
|
it 'should format as a single block' do
|
153
|
-
Phony.format('
|
167
|
+
Phony.format('88132155605220').should == '+881 32155605220'
|
154
168
|
end
|
155
169
|
it 'should format as a single block, regardless of format' do
|
156
|
-
Phony.format('
|
170
|
+
Phony.format('8811819372205', :format => :international).should == '+881 1819372205'
|
157
171
|
end
|
158
172
|
it 'should format as a single block, respecting custom spaces' do
|
159
|
-
Phony.format('
|
173
|
+
Phony.format('8811819372205', :spaces => :-).should == '+881-1819372205'
|
160
174
|
end
|
161
175
|
it 'should format as a single block, even without spaces' do
|
162
|
-
Phony.format('
|
176
|
+
Phony.format('8811819372205', :spaces => '').should == '+8811819372205'
|
163
177
|
end
|
164
178
|
end
|
165
179
|
end
|
@@ -219,10 +233,10 @@ describe Phony do
|
|
219
233
|
end
|
220
234
|
context '"unsupported" countries' do
|
221
235
|
it 'handles formatting' do
|
222
|
-
Phony.format('
|
236
|
+
Phony.format('88132155605220').should == '+881 32155605220'
|
223
237
|
end
|
224
238
|
it 'handles normalizing' do
|
225
|
-
Phony.normalize('+
|
239
|
+
Phony.normalize('+881-321 5560 5220').should == '88132155605220'
|
226
240
|
end
|
227
241
|
end
|
228
242
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0.beta1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Florian Hanke
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'Fast international phone number (E164 standard) normalizing, splitting
|
15
15
|
and formatting. Lots of formatting options: International (+.., 00..), national
|
@@ -21,17 +21,40 @@ extra_rdoc_files:
|
|
21
21
|
- README.textile
|
22
22
|
files:
|
23
23
|
- lib/phony/countries/austria.rb
|
24
|
+
- lib/phony/countries/bangladesh.rb
|
25
|
+
- lib/phony/countries/belarus.rb
|
24
26
|
- lib/phony/countries/brazil.rb
|
25
27
|
- lib/phony/countries/china.rb
|
28
|
+
- lib/phony/countries/georgia.rb
|
26
29
|
- lib/phony/countries/germany.rb
|
30
|
+
- lib/phony/countries/india.rb
|
31
|
+
- lib/phony/countries/indonesia.rb
|
27
32
|
- lib/phony/countries/ireland.rb
|
28
33
|
- lib/phony/countries/italy.rb
|
34
|
+
- lib/phony/countries/japan.rb
|
35
|
+
- lib/phony/countries/kyrgyzstan.rb
|
36
|
+
- lib/phony/countries/latvia.rb
|
37
|
+
- lib/phony/countries/libya.rb
|
29
38
|
- lib/phony/countries/malaysia.rb
|
39
|
+
- lib/phony/countries/moldova.rb
|
40
|
+
- lib/phony/countries/montenegro.rb
|
41
|
+
- lib/phony/countries/namibia.rb
|
42
|
+
- lib/phony/countries/nepal.rb
|
30
43
|
- lib/phony/countries/netherlands.rb
|
44
|
+
- lib/phony/countries/pakistan.rb
|
45
|
+
- lib/phony/countries/paraguay.rb
|
31
46
|
- lib/phony/countries/russia_kazakhstan_abhasia_south_osetia.rb
|
47
|
+
- lib/phony/countries/serbia.rb
|
48
|
+
- lib/phony/countries/somali.rb
|
32
49
|
- lib/phony/countries/south_korea.rb
|
33
50
|
- lib/phony/countries/sweden.rb
|
51
|
+
- lib/phony/countries/taiwan.rb
|
52
|
+
- lib/phony/countries/tajikistan.rb
|
53
|
+
- lib/phony/countries/turkmenistan.rb
|
54
|
+
- lib/phony/countries/ukraine.rb
|
34
55
|
- lib/phony/countries/united_kingdom.rb
|
56
|
+
- lib/phony/countries/uruguay.rb
|
57
|
+
- lib/phony/countries/zimbabwe.rb
|
35
58
|
- lib/phony/countries.rb
|
36
59
|
- lib/phony/country.rb
|
37
60
|
- lib/phony/country_codes.rb
|
@@ -45,8 +68,6 @@ files:
|
|
45
68
|
- lib/phony/national_splitters/none.rb
|
46
69
|
- lib/phony/national_splitters/regex.rb
|
47
70
|
- lib/phony/national_splitters/variable.rb
|
48
|
-
- lib/phony/validator.rb
|
49
|
-
- lib/phony/validators.rb
|
50
71
|
- lib/phony/vanity.rb
|
51
72
|
- lib/phony.rb
|
52
73
|
- README.textile
|
@@ -79,12 +100,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
101
|
none: false
|
81
102
|
requirements:
|
82
|
-
- - ! '
|
103
|
+
- - ! '>'
|
83
104
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
105
|
+
version: 1.3.1
|
85
106
|
requirements: []
|
86
107
|
rubyforge_project:
|
87
|
-
rubygems_version: 1.8.
|
108
|
+
rubygems_version: 1.8.10
|
88
109
|
signing_key:
|
89
110
|
specification_version: 3
|
90
111
|
summary: Fast international phone number (E164 standard) normalizing, splitting and
|
@@ -104,4 +125,3 @@ test_files:
|
|
104
125
|
- spec/lib/phony/validations_spec.rb
|
105
126
|
- spec/lib/phony/vanity_spec.rb
|
106
127
|
- spec/lib/phony_spec.rb
|
107
|
-
has_rdoc: false
|
data/lib/phony/validator.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Phony
|
2
|
-
|
3
|
-
class Validator
|
4
|
-
|
5
|
-
attr_reader :ndc_checks
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@ndc_checks = []
|
9
|
-
end
|
10
|
-
|
11
|
-
def plausible? ndc, rest
|
12
|
-
ndc_checks && ndc_checks.each do |ndc_check|
|
13
|
-
return false if ndc_check === ndc
|
14
|
-
end
|
15
|
-
|
16
|
-
true
|
17
|
-
end
|
18
|
-
|
19
|
-
def ndc_check ndc
|
20
|
-
@ndc_checks << ndc
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
data/lib/phony/validators.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
# # Number: A possible phone number, E164 or not.
|
2
|
-
# # Hints: Information that helps or constricts the plausibility check.
|
3
|
-
# #
|
4
|
-
# plausible? number, hints = {}
|
5
|
-
#
|
6
|
-
|
7
|
-
# plausible? number # Uses the definitions from the country definition to plausibility check.
|
8
|
-
# plausible? number, cc: 1 # => Checks cc.
|
9
|
-
# plausible? number, pattern: /[^5]/ # Uses def, checks against split.
|
10
|
-
# plausible? number, country: 1, pattern: [3, 4, 3] # Uses given country – adds cc.
|
11
|
-
#
|
12
|
-
|
13
|
-
# Basic plausibility is:
|
14
|
-
# * Max digits are 15.
|
15
|
-
# * Min digits are 2 (?)
|
16
|
-
#
|
17
|
-
|
18
|
-
module Phony
|
19
|
-
|
20
|
-
class Validators
|
21
|
-
|
22
|
-
def initialize
|
23
|
-
@validators = {}
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.instance
|
27
|
-
@instance ||= new
|
28
|
-
end
|
29
|
-
|
30
|
-
# Add a specific country validator.
|
31
|
-
#
|
32
|
-
def add cc, validator
|
33
|
-
@validators[cc] = validator
|
34
|
-
end
|
35
|
-
|
36
|
-
# Is the given number plausible?
|
37
|
-
#
|
38
|
-
def plausible? number, hints = {}
|
39
|
-
normalized = CountryCodes.instance.clean number
|
40
|
-
|
41
|
-
# False if it fails the basic check.
|
42
|
-
#
|
43
|
-
return false unless (4..15) === normalized.size
|
44
|
-
|
45
|
-
# Hint based checking.
|
46
|
-
#
|
47
|
-
cc, ndc, *rest = Phony.split normalized
|
48
|
-
|
49
|
-
# Element based checking.
|
50
|
-
#
|
51
|
-
# Note: ndc == false means the country has none.
|
52
|
-
#
|
53
|
-
return false if ndc.nil?
|
54
|
-
return false if ndc && ndc.empty?
|
55
|
-
|
56
|
-
# A valid range for the rest is 0 or 3+ total digits.
|
57
|
-
#
|
58
|
-
return false if (1..2) === rest.reduce(0) { |total, string| total + string.size }
|
59
|
-
|
60
|
-
# CC.
|
61
|
-
#
|
62
|
-
cc_needed = hints[:cc]
|
63
|
-
return false if cc_needed && !(cc_needed === cc)
|
64
|
-
|
65
|
-
# NDC.
|
66
|
-
#
|
67
|
-
ndc_needed = hints[:ndc]
|
68
|
-
return false if ndc_needed && !(ndc_needed === ndc)
|
69
|
-
|
70
|
-
# Country specific checks.
|
71
|
-
#
|
72
|
-
validator = validator_for cc
|
73
|
-
validator.plausible? ndc, rest
|
74
|
-
rescue StandardError
|
75
|
-
return false
|
76
|
-
end
|
77
|
-
|
78
|
-
def validator_for cc
|
79
|
-
@validators[cc] || default_validator
|
80
|
-
end
|
81
|
-
|
82
|
-
def default_validator
|
83
|
-
@default_validator ||= Validator.new
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|