phone_classifier 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -3,6 +3,8 @@ Phone Classifier
3
3
 
4
4
  Used to quickly classifiy a phone number into :landline, :mobile or :forbidden
5
5
 
6
+ Current Travis Build Status: [![Build Status](https://secure.travis-ci.org/mobino/phone_classifier.png?branch=master)](https://travis-ci.org/mobino/phone_classifier)
7
+
6
8
  Installation
7
9
  ------------
8
10
 
@@ -20,8 +22,6 @@ Supported Countries
20
22
  -------------------
21
23
 
22
24
  * +1, USA (will only reject service numbers, all other numbers considered mobile). Blame the US numbering systems
23
- * +6, Greece
24
- * +31, Netherlands
25
25
  * +30, Greece
26
26
  * +31, Netherlands
27
27
  * +32, Belgium
@@ -38,6 +38,8 @@ Supported Countries
38
38
  * +47, Norway
39
39
  * +48, Poland
40
40
  * +49, Germany
41
+ * +60, Malaysia
42
+ * +65, Singapore
41
43
  * +212, Morocco
42
44
  * +213, Algeria
43
45
  * +233, Ghana
@@ -63,12 +65,12 @@ Supported Countries
63
65
  Where is it used
64
66
  ----------------
65
67
 
66
- Used in Mobino[http://mobino.com], a mobile payment service, to classifiy client phone numbers
68
+ Used in [Mobino](http://mobino.com), a mobile payment service, to classifiy client phone numbers
67
69
 
68
70
  Related
69
71
  -------
70
72
 
71
- PhoneClassifier uses the fantastic 'Phony'[http://github.com/floere/phony.git] library to normalize numbers. Phony is
73
+ PhoneClassifier uses the fantastic [Phony](http://github.com/floere/phony.git) library to normalize numbers. Phony is
72
74
  the tool of choice if you need to work with phone numbers in Ruby.
73
75
 
74
76
  Contributing
@@ -0,0 +1,49 @@
1
+
2
+
3
+ module Forbidden
4
+
5
+ def self.data
6
+ @@forbidden ||= {
7
+ '1' => %w{ 1.. }, # USA
8
+ '30' => %w{ 8.. 9.. }, # Greece
9
+ '31' => %w{84 85 87 88 91 112 676 800 900 906 909}, # Netherlands
10
+ '32' => %w{70 800 90[0-9]}, # Belgium
11
+ '33' => %w{8}, # France
12
+ '34' => %w{10 11 80 90}, # Spain
13
+ '36' => %w{ 40 41 50 55 60 71 80 90 91 }, # Hungary
14
+ '39' => %w{1 7 8}, # Italy
15
+ '40' => %w{ 8. 9. }, # Romania
16
+ '41' => %w{ 74 800 840 842 844 848 860 868 900 901 906 }, # Switzerland
17
+ '43' => %w{ 718 720 780 8.. 9.. }, # Austria
18
+ '44' => %w{800 808 842 843 844 845 870 871 872 873 900 908 909 982}, # UK
19
+ '45' => %w{10 11 18 70 80 90}, # Denmark
20
+ '46' => %w{ 900 939 944 99. },
21
+ '47' => %w{ 8.. }, # Norway
22
+ '48' => %w{70., 80.}, # Poland
23
+ '49' => %w{ 1. 164 168 169 180 181 19[0-4] 800 900 }, # Germany
24
+ '60' => %w{ 100 101 102 103 104 108 112 991 994 995 999 }, # Malaysia
25
+ '65' => %w{ 3... 800 1800 1900 }, # Singapore
26
+ '212' => %w{ 8. }, # Morocco
27
+ '213' => %w{ 8.. 9.. }, # Algeria
28
+ '233' => %w{ 1 4 6 7 8 9 }, # Ghana
29
+ '234' => %w{ 8.. 9.. }, # Nigeria
30
+ '249' => %w{ }, # Sudan
31
+ '350' => %w{ 8... }, # Gibraltar
32
+ '351' => %w{ 800 80. }, # Portugal
33
+ '352' => %w{ 118 12 13 800 801 900 901 905 }, # Luxembourg
34
+ '353' => %w{ 76 80 81 800 }, # Ireland
35
+ '354' => %w{ 8.. 9.. }, # Iceland
36
+ '356' => %w{ }, # Malta
37
+ '357' => %w{ 80 90 }, # Cyprus
38
+ '358' => %w{ 6.. 7.. 8.. }, # Finland
39
+ '359' => %w{ 800 900 }, # Bulgaria
40
+ '370' => %w{ 800 9.. }, # Lithuania
41
+ '372' => %w{ 1.. 800 }, # Estonia
42
+ '377' => %w{ }, # Monaco
43
+ '386' => %w{ 80 89 90 }, # Slovenia
44
+ '420' => %w{ 8.. 9.. }, # Czech republic
45
+ '421' => %w{ }, # Slovakia
46
+ }
47
+ end
48
+ end
49
+
@@ -0,0 +1,49 @@
1
+
2
+
3
+ module Mobile
4
+
5
+ def self.data
6
+ @@mobile ||= {
7
+ '1' => %w{ [2-9].. }, # USA
8
+ '30' => %w{ 6.. }, # Greece
9
+ '31' => %w{6}, # Netherlands
10
+ '32' => %w{4..}, # Belgium
11
+ '33' => %w{6 7}, # France
12
+ '34' => %w{6. 7.}, # Spain
13
+ '36' => %w{ 20 30 31 70 }, # Hungary
14
+ '39' => %w{3...}, # Italy
15
+ '40' => %w{ 7. }, # Romania
16
+ '41' => %w{ 7[6-9] }, # Switerzland
17
+ '43' => %w{ 67 68 644 65. 66. }, # Austria
18
+ '44' => %w{ 7[4-9].. }, # UK
19
+ '45' => %w{ 2[0-9] 30 31 40 41 42 5[0-3] 60 61 71 81 9[1-3] }, # Denmark
20
+ '46' => %w{ 70 72 73 76 }, # Sweden
21
+ '47' => %w{ 9.. 4.. 58. 59. }, # Norway
22
+ '48' => %w{50. 51. 53. 60. 66. 69. 72. 78. 79. 88.}, # Poland
23
+ '49' => %w{ 151 152 157 159 160 162 163 17[0-9] }, # Germany
24
+ '60' => %w{ 10 11 12 13 14 153 154 156 158 16 17 18 19 }, # Malaysia
25
+ '65' => %w{ 8... 9... }, # Singapore
26
+ '212' => %w{ 6. }, # Morocco
27
+ '213' => %w{ 55 66 697 699 77 790 796 }, # Algeria
28
+ '233' => %w{ 20 23 24 26 27 28 50 54 57 }, # Ghana
29
+ '234' => %w{ 702[1-9] 70[3-9] 8[01][2-9] }, # Nigeria
30
+ '249' => %w{ 9. }, # Sudan
31
+ '350' => %w{ 5. 6. }, # Gibraltar
32
+ '351' => %w{ 9. }, # Portugal
33
+ '352' => %w{ 621 628 661 668 691 698 }, # Luxembourg
34
+ '353' => %w{ 8[2-9] }, # Ireland
35
+ '354' => %w{ 6.. 7.. 8..}, # Iceland
36
+ '356' => %w{ 77 79 98 99 }, # Malta
37
+ '357' => %w{ 95 96 97 99 }, # Cyprus
38
+ '358' => %w{ 4. 50 }, # Finland
39
+ '359' => %w{ 430 87. 88. 89. 98. }, # Bulgaria
40
+ '370' => %w{ 6.. }, # Lithuania
41
+ '372' => %w{ 5.. 81. 82.}, # Estonia
42
+ '377' => %w{ 4. 6 }, # Monaco
43
+ '386' => %w{ 30 40 31 41 51 71 70 64}, # Slovenia
44
+ '420' => %w{ 60[1-8] 72. 73. 77. 79. 91 }, # Czech Republic
45
+ '421' => %w{ 9.. }, # Slovakia
46
+ }
47
+ end
48
+ end
49
+
@@ -1,89 +1,14 @@
1
1
  require 'phony'
2
2
 
3
+
4
+ require 'phone_classifier/mobile'
5
+ require 'phone_classifier/forbidden'
6
+
3
7
  class PhoneClassifier
4
8
 
5
9
  # authorative info: http://www.itu.int/oth/T0202.aspx?parent=T0202
6
10
  # Numbering schemes for mobile numbers
7
11
  #
8
- @@mobile = {
9
- '1' => %w{ [2-9].. }, # USA
10
- '30' => %w{ 6.. }, # Greece
11
- '31' => %w{6}, # Netherlands
12
- '32' => %w{4..}, # Belgium
13
- '33' => %w{6 7}, # France
14
- '34' => %w{6. 7.}, # Spain
15
- '36' => %w{ 20 30 31 70 }, # Hungary
16
- '39' => %w{3...}, # Italy
17
- '40' => %w{ 7. }, # Romania
18
- '41' => %w{ 7[6-9] }, # Switerzland
19
- '43' => %w{ 67 68 644 65. 66. }, # Austria
20
- '44' => %w{ 7[4-9].. }, # UK
21
- '45' => %w{ 2[0-9] 30 31 40 41 42 5[0-3] 60 61 71 81 9[1-3] }, # Denmark
22
- '46' => %w{ 70 72 73 76 }, # Sweden
23
- '47' => %w{ 9.. 4.. 58. 59. }, # Norway
24
- '48' => %w{50. 51. 53. 60. 66. 69. 72. 78. 79. 88.}, # Poland
25
- '49' => %w{ 151 152 157 159 160 162 163 17[0-9] }, # Germany
26
- '212' => %w{ 6. }, # Morocco
27
- '213' => %w{ 55 66 697 699 77 790 796 }, # Algeria
28
- '233' => %w{ 20 23 24 26 27 28 50 54 57 },
29
- '234' => %w{ 702[1-9] 70[3-9] 8[01][2-9] },
30
- '249' => %w{ 9. }, # Sudan
31
- '350' => %w{ 5. 6. }, # Gibraltar
32
- '351' => %w{ 9. }, # Portugal
33
- '352' => %w{ 621 628 661 668 691 698 }, # Luxembourg
34
- '353' => %w{ 8[2-9] }, # Ireland
35
- '354' => %w{ 6.. 7.. 8..}, # Iceland
36
- '356' => %w{ 77 79 98 99 }, # Malta
37
- '357' => %w{ 95 96 97 99 }, # Cyprus
38
- '358' => %w{ 4. 50 }, # Finland
39
- '359' => %w{ 430 87. 88. 89. 98. }, # Bulgaria
40
- '370' => %w{ 6.. }, # Lithuania
41
- '372' => %w{ 5.. 81. 82.}, # Estonia
42
- '377' => %w{ 4. 6 }, # Monaco
43
- '386' => %w{ 30 40 31 41 51 71 70 64}, # Slovenia
44
- '420' => %w{ 60[1-8] 72. 73. 77. 79. 91 }, # Czech Republic
45
- '421' => %w{ 9.. }, # Slovakia
46
- }
47
-
48
- @@forbidden = {
49
- '1' => %w{ 1.. }, # USA
50
- '30' => %w{ 8.. 9.. }, # Greece
51
- '31' => %w{84 85 87 88 91 112 676 800 900 906 909}, # Netherlands
52
- '32' => %w{70 800 90[0-9]}, # Belgium
53
- '33' => %w{8}, # France
54
- '34' => %w{10 11 80 90}, # Spain
55
- '36' => %w{ 40 41 50 55 60 71 80 90 91 }, # Hungary
56
- '39' => %w{1 7 8}, # Italy
57
- '40' => %w{ 8. 9. }, # Romania
58
- '41' => %w{ 74 800 840 842 844 848 860 868 900 901 906 }, # Switzerland
59
- '43' => %w{ 718 720 780 8.. 9.. }, # Austria
60
- '44' => %w{800 808 842 843 844 845 870 871 872 873 900 908 909 982}, # UK
61
- '45' => %w{10 11 18 70 80 90}, # Denmark
62
- '46' => %w{ 900 939 944 99. },
63
- '47' => %w{ 8.. }, # Norway
64
- '48' => %w{70., 80.}, # Poland
65
- '49' => %w{ 1. 164 168 169 180 181 19[0-4] 800 900 }, # Germany
66
- '212' => %w{ 8. }, # Morocco
67
- '213' => %w{ 8.. 9.. }, # Algeria
68
- '233' => %w{ 1 4 6 7 8 9 },
69
- '234' => %w{ 8.. 9.. },
70
- '249' => %w{ }, # Sudan
71
- '350' => %w{ 8... }, # Gibraltar
72
- '351' => %w{ 800 80. }, # Portugal
73
- '352' => %w{ 118 12 13 800 801 900 901 905 }, # Luxembourg
74
- '353' => %w{ 76 80 81 800 }, # Ireland
75
- '354' => %w{ 8.. 9.. }, # Iceland
76
- '356' => %w{ }, # Malta
77
- '357' => %w{ 80 90 }, # Cyprus
78
- '358' => %w{ 6.. 7.. 8.. }, # Finland
79
- '359' => %w{ 800 900 }, # Bulgaria
80
- '370' => %w{ 800 9.. }, # Lithuania
81
- '372' => %w{ 1.. 800 }, # Estonia
82
- '377' => %w{ }, # Monaco
83
- '386' => %w{ 80 89 90 }, # Slovenia
84
- '420' => %w{ 8.. 9.. }, # Czech republic
85
- '421' => %w{ }, # Slovakia
86
- }
87
12
 
88
13
  def initialize number
89
14
  @number = number
@@ -101,12 +26,12 @@ class PhoneClassifier
101
26
  end
102
27
 
103
28
  def mobile?
104
- return is_number_of_type @@mobile
29
+ return is_number_of_type Mobile.data
105
30
  end
106
31
 
107
32
 
108
33
  def forbidden?
109
- return is_number_of_type @@forbidden
34
+ return is_number_of_type Forbidden.data
110
35
  end
111
36
 
112
37
  def is_number_of_type numbers
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Forbidden do
4
+
5
+ it 'has a data method' do
6
+ Forbidden.data.should be_instance_of(Hash)
7
+ end
8
+
9
+
10
+ it 'has data for country with ndc 1' do
11
+ Forbidden.data['1'].should be_instance_of(Array)
12
+ end
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mobile do
4
+
5
+ it 'has a data method' do
6
+ Mobile.data.should be_instance_of(Hash)
7
+ end
8
+
9
+
10
+ it 'has data for country with ndc 1' do
11
+ Mobile.data['1'].should be_instance_of(Array)
12
+ end
13
+
14
+ end
@@ -294,4 +294,34 @@ describe PhoneClassifier do
294
294
 
295
295
  end
296
296
 
297
+ context "Malaysian Numbers" do
298
+
299
+ it "should set Malaysian mobile numbers" do
300
+ phone_number = "60 11 1234 5678"
301
+ PhoneClassifier.new(phone_number).kind.should == :mobile
302
+ end
303
+
304
+ it "should set Malaysian service numbers " do
305
+ phone_number = "60 999 123 123"
306
+ PhoneClassifier.new(phone_number).kind.should == :forbidden
307
+ end
308
+
309
+
310
+ end
311
+
312
+ context "Singapore Numbers" do
313
+
314
+ it "should set mobile numbers" do
315
+ phone_number = "65 8123 1234"
316
+ PhoneClassifier.new(phone_number).kind.should == :mobile
317
+ end
318
+
319
+ it "should set service numbers " do
320
+ phone_number = "65 3123 1234"
321
+ PhoneClassifier.new(phone_number).kind.should == :forbidden
322
+ end
323
+
324
+
325
+ end
326
+
297
327
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phone_classifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
4
  prerelease:
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jens-Christian Fischer
@@ -12,21 +12,21 @@ cert_chain: []
12
12
  date: 2012-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: phony
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
15
+ version_requirements: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.8'
20
+ none: false
21
+ name: phony
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
24
+ requirement: !ruby/object:Gem::Requirement
26
25
  requirements:
27
26
  - - ~>
28
27
  - !ruby/object:Gem::Version
29
28
  version: '1.8'
29
+ none: false
30
30
  description: Classifies some countries phone numbers into :mobile, :forbidden and
31
31
  :landline
32
32
  email: jcf+phone_classifier@mobino.com
@@ -35,8 +35,12 @@ extensions: []
35
35
  extra_rdoc_files:
36
36
  - README.md
37
37
  files:
38
+ - lib/phone_classifier/forbidden.rb
39
+ - lib/phone_classifier/mobile.rb
38
40
  - lib/phone_classifier.rb
39
41
  - README.md
42
+ - spec/phone_classifier/forbidden_spec.rb
43
+ - spec/phone_classifier/mobile_spec.rb
40
44
  - spec/phone_classifier_spec.rb
41
45
  homepage: http://github.com/mobino/phone_classifier
42
46
  licenses: []
@@ -45,17 +49,17 @@ rdoc_options: []
45
49
  require_paths:
46
50
  - lib
47
51
  required_ruby_version: !ruby/object:Gem::Requirement
48
- none: false
49
52
  requirements:
50
53
  - - ! '>='
51
54
  - !ruby/object:Gem::Version
52
55
  version: '0'
53
- required_rubygems_version: !ruby/object:Gem::Requirement
54
56
  none: false
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
58
  requirements:
56
59
  - - ! '>='
57
60
  - !ruby/object:Gem::Version
58
61
  version: '0'
62
+ none: false
59
63
  requirements: []
60
64
  rubyforge_project:
61
65
  rubygems_version: 1.8.23
@@ -63,4 +67,6 @@ signing_key:
63
67
  specification_version: 3
64
68
  summary: Classification of phone numbers
65
69
  test_files:
70
+ - spec/phone_classifier/forbidden_spec.rb
71
+ - spec/phone_classifier/mobile_spec.rb
66
72
  - spec/phone_classifier_spec.rb