mobile_number_normalizer 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,7 +16,7 @@ class MobileNumberNormalizer
16
16
  # Array of String of International Area Codes
17
17
  #
18
18
  # @author dmasur
19
- VALID_INTERNATIONAL_AREA_CODE = [ '001', '001809', '0020', '00212', '00213', '00216', '00218',
19
+ @@valid_area_codes = [ '001', '001809', '0020', '00212', '00213', '00216', '00218',
20
20
  '00220', '00221', '00222', '00223', '00224', '00225', '00226',
21
21
  '00227', '00228', '00229', '00230', '00231', '00232', '00233',
22
22
  '00234', '00235', '00236', '00237', '00238', '00239', '00240',
@@ -43,7 +43,15 @@ class MobileNumberNormalizer
43
43
  '00962', '00963', '00964', '00965', '00966', '00967', '00968',
44
44
  '00971', '00972', '00973', '00974', '00975', '00976', '00977',
45
45
  '0098', '00994' ]
46
- def initialize(mobile_number)
46
+ def self.valid_area_codes=(new_valid_area_codes)
47
+ @@valid_area_codes = new_valid_area_codes
48
+ end
49
+
50
+ def self.valid_area_codes
51
+ @@valid_area_codes
52
+ end
53
+
54
+ def initialize(mobile_number, valid_area_codes = [])
47
55
  @mobile_number = mobile_number
48
56
  end
49
57
 
@@ -52,7 +60,6 @@ class MobileNumberNormalizer
52
60
  #
53
61
  # @author dmasur
54
62
  def self.get_number number
55
- $delete_mobile_numbers ||= []
56
63
  number = new(number).get_number
57
64
  return number
58
65
  end
@@ -71,7 +78,6 @@ class MobileNumberNormalizer
71
78
  clean_mobile_number
72
79
  #puts "After clean: #{@mobile_number}"
73
80
  mobile_number = "" unless has_valid_area_code?
74
- $delete_mobile_numbers << org_num if @mobile_number.blank? && !org_num.blank?
75
81
  return @mobile_number
76
82
  end
77
83
 
@@ -166,7 +172,7 @@ class MobileNumberNormalizer
166
172
  end
167
173
 
168
174
  def has_valid_area_code?
169
- VALID_INTERNATIONAL_AREA_CODE.any? do |area_code|
175
+ self.class.valid_area_codes.any? do |area_code|
170
176
  Regexp.new("^#{area_code}") =~ @mobile_number
171
177
  end
172
178
  end
@@ -180,7 +186,7 @@ class MobileNumberNormalizer
180
186
  mobile_number = "0#{mobile_number}" if /^1/ =~ mobile_number
181
187
  mobile_number.sub!(/^49/, '0049')
182
188
  mobile_number.sub!(/\+/, '00')
183
- VALID_INTERNATIONAL_AREA_CODE.each do |area_code|
189
+ valid_area_codes.each do |area_code|
184
190
  if mobile_number.start_with?(area_code[2..-1])
185
191
  mobile_number = "00#{mobile_number}"
186
192
  end
@@ -1,3 +1,3 @@
1
1
  class MobileNumberNormalizer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -166,6 +166,10 @@ describe MobileNumberNormalizer do
166
166
  MobileNumberNormalizer.get_number("0049 176 12345678; 0043 6712345678").
167
167
  should == "004917612345678"
168
168
  end
169
+ it "give number for 123456" do
170
+ MobileNumberNormalizer.get_number("123456").
171
+ should be_blank
172
+ end
169
173
  end
170
174
  describe "area codes" do
171
175
  it "should accept right area code" do
metadata CHANGED
@@ -1,74 +1,71 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mobile_number_normalizer
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Dominik Masur
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-29 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-10-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rspec
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :development
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: active_support
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
38
25
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: active_support
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
46
38
  type: :development
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: rake
50
39
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
52
41
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
60
54
  type: :development
61
- version_requirements: *id003
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
62
  description: Normalize mobile Phone Numbers
63
- email:
63
+ email:
64
64
  - dominik.masur@googlemail.com
65
65
  executables: []
66
-
67
66
  extensions: []
68
-
69
67
  extra_rdoc_files: []
70
-
71
- files:
68
+ files:
72
69
  - .gitignore
73
70
  - .rspec
74
71
  - .travis.yml
@@ -84,37 +81,34 @@ files:
84
81
  - spec/spec_helper.rb
85
82
  homepage: https://github.com/TBAA/mobile_number_normalizer
86
83
  licenses: []
87
-
88
84
  post_install_message:
89
85
  rdoc_options: []
90
-
91
- require_paths:
86
+ require_paths:
92
87
  - lib
93
- required_ruby_version: !ruby/object:Gem::Requirement
88
+ required_ruby_version: !ruby/object:Gem::Requirement
94
89
  none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
100
95
  - 0
101
- version: "0"
102
- required_rubygems_version: !ruby/object:Gem::Requirement
96
+ hash: 34214004847796006
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
98
  none: false
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- hash: 3
108
- segments:
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
109
104
  - 0
110
- version: "0"
105
+ hash: 34214004847796006
111
106
  requirements: []
112
-
113
107
  rubyforge_project:
114
- rubygems_version: 1.8.10
108
+ rubygems_version: 1.8.24
115
109
  signing_key:
116
110
  specification_version: 3
117
111
  summary: Normalize mobile Phone Numbers
118
- test_files:
112
+ test_files:
119
113
  - spec/lib/mobile_number_normalizer_spec.rb
120
114
  - spec/spec_helper.rb