phone_classifier 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/phone_classifier.rb +9 -5
- data/lib/phone_classifier/mobile.rb +3 -3
- data/spec/phone_classifier_spec.rb +19 -3
- metadata +2 -2
data/lib/phone_classifier.rb
CHANGED
@@ -36,16 +36,20 @@ class PhoneClassifier
|
|
36
36
|
|
37
37
|
def is_number_of_type numbers
|
38
38
|
parts = Phony.split Phony.normalize(@number)
|
39
|
-
|
39
|
+
ndcs = numbers[parts.shift]
|
40
40
|
prefix = parts.shift
|
41
41
|
|
42
|
-
#
|
43
|
-
|
44
|
-
|
42
|
+
return false unless ndcs # if we don't know the country, we can make no assumptions
|
43
|
+
|
44
|
+
# countries without NDCs (Denmark) have this parts structure ["45", false, "40", "53", "25", "77"]
|
45
|
+
until parts.size == 0 || prefix.is_a?(String)
|
45
46
|
prefix = parts.shift
|
47
|
+
|
46
48
|
end
|
47
49
|
|
48
|
-
|
50
|
+
|
51
|
+
ndcs.each { |n| return true if prefix.match(/^#{n}$/) } unless ndcs.nil?
|
52
|
+
|
49
53
|
false
|
50
54
|
end
|
51
55
|
|
@@ -6,12 +6,12 @@
|
|
6
6
|
@@mobile ||= {
|
7
7
|
'1' => %w{ [2-9].. }, # USA
|
8
8
|
'30' => %w{ 6.. }, # Greece
|
9
|
-
'31' => %w{6}, # Netherlands
|
9
|
+
'31' => %w{ 6 }, # Netherlands
|
10
10
|
'32' => %w{4..}, # Belgium
|
11
11
|
'33' => %w{6 7}, # France
|
12
12
|
'34' => %w{6. 7.}, # Spain
|
13
13
|
'36' => %w{ 20 30 31 70 }, # Hungary
|
14
|
-
'39' => %w{3
|
14
|
+
'39' => %w{3..}, # Italy
|
15
15
|
'40' => %w{ 7. }, # Romania
|
16
16
|
'41' => %w{ 7[6-9] }, # Switerzland
|
17
17
|
'43' => %w{ 67 68 644 65. 66. }, # Austria
|
@@ -26,7 +26,7 @@
|
|
26
26
|
'91' => %w{ 91 92 93 94 97 98 99 }, # India
|
27
27
|
'94' => %w{ 71 72 75 77 78 }, # Sri Lanka
|
28
28
|
'98' => %w{ 91. 92. 93. } , #Iran
|
29
|
-
'212' => %w{ 6
|
29
|
+
'212' => %w{ 6 }, # Morocco
|
30
30
|
'213' => %w{ 55 66 697 699 77 790 796 }, # Algeria
|
31
31
|
'233' => %w{ 20 23 24 26 27 28 50 54 57 }, # Ghana
|
32
32
|
'234' => %w{ 702[1-9] 70[3-9] 8[01][2-9] }, # Nigeria
|
@@ -5,6 +5,12 @@ require 'spec_helper'
|
|
5
5
|
|
6
6
|
describe PhoneClassifier do
|
7
7
|
|
8
|
+
context 'it handles invalid number' do
|
9
|
+
it 'does not timeout' do
|
10
|
+
PhoneClassifier.new('52726').kind.should == :landline
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
8
14
|
context "it classifies a phone number" do
|
9
15
|
|
10
16
|
let(:phone_number) { "41791234567" }
|
@@ -336,9 +342,19 @@ describe PhoneClassifier do
|
|
336
342
|
PhoneClassifier.new(phone_number).kind.should == :mobile
|
337
343
|
end
|
338
344
|
|
339
|
-
|
340
|
-
|
341
|
-
|
345
|
+
|
346
|
+
end
|
347
|
+
|
348
|
+
context "Moroccon Numbers" do
|
349
|
+
|
350
|
+
it "should set Moroocan mobile numbers" do
|
351
|
+
phone_number = "212 6 52 22 11 44"
|
352
|
+
PhoneClassifier.new(phone_number).kind.should == :mobile
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should set Morocoan landline numbers " do
|
356
|
+
phone_number = "212 45 1234 123"
|
357
|
+
PhoneClassifier.new(phone_number).kind.should == :landline
|
342
358
|
end
|
343
359
|
|
344
360
|
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: phone_classifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jens-Christian Fischer
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|