mobile_number_normalizer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/lib/mobile_number_normalizer/version.rb +3 -0
- data/lib/mobile_number_normalizer.rb +200 -0
- data/mobile_number_normalizer.gemspec +21 -0
- data/spec/lib/mobile_number_normalizer_spec.rb +178 -0
- data/spec/spec_helper.rb +11 -0
- metadata +120 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Dominik Masur
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# MobileNumberNormalizer
|
2
|
+
[![Build Status](https://secure.travis-ci.org/TBAA/mobile_number_normalizer.png?branch=master)](http://travis-ci.org/TBAA/mobile_number_normalizer)
|
3
|
+
This Gem introduce a MobileNumberNormalizer. It normalize mobile phone numbers and was tested againt
|
4
|
+
many german and international mobile numbers.
|
5
|
+
|
6
|
+
Numbers without international area prefix will be prefixed with 0049 for germany.
|
7
|
+
|
8
|
+
Please take a look at the spec file for many examples.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'mobile_number_normalizer'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install mobile_number_normalizer
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
MobileNumberNormalizer.get_number("01771234567")
|
27
|
+
# => "00491771234567"
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
##
|
3
|
+
# Normalize Mobile Numbers
|
4
|
+
#
|
5
|
+
# @author dmasur
|
6
|
+
class MobileNumberNormalizer
|
7
|
+
##
|
8
|
+
# Minimal Length of a Mobile Number
|
9
|
+
# 0049 => 4
|
10
|
+
# 177 => 3
|
11
|
+
# xxxxxx => minimal 4
|
12
|
+
#
|
13
|
+
# @author dmasur
|
14
|
+
MIN_MOBILE_NUMBER_LENGTH = 11
|
15
|
+
##
|
16
|
+
# Array of String of International Area Codes
|
17
|
+
#
|
18
|
+
# @author dmasur
|
19
|
+
VALID_INTERNATIONAL_AREA_CODE = [ '001', '001809', '0020', '00212', '00213', '00216', '00218',
|
20
|
+
'00220', '00221', '00222', '00223', '00224', '00225', '00226',
|
21
|
+
'00227', '00228', '00229', '00230', '00231', '00232', '00233',
|
22
|
+
'00234', '00235', '00236', '00237', '00238', '00239', '00240',
|
23
|
+
'00241', '00242', '00243', '00244', '00245', '00247', '00248',
|
24
|
+
'00249', '00250', '00251', '00252', '00253', '00254', '00255',
|
25
|
+
'00256', '00257', '00258', '00260', '00261', '00262', '00263',
|
26
|
+
'00264', '00265', '00266', '00267', '00268', '00269', '0027',
|
27
|
+
'00290', '00291', '00297', '00298', '00299', '0030', '0031',
|
28
|
+
'0032', '0033', '0034', '00350', '00351', '00352', '00353',
|
29
|
+
'00354', '00355', '00356', '00357', '00358', '00359', '0036',
|
30
|
+
'00370', '00371', '00372', '00373', '00376', '00378', '0038',
|
31
|
+
'00385', '00387', '00389', '0039', '00396', '0040', '0041',
|
32
|
+
'0042', '0043', '0044', '0045', '0046', '0047', '0048', '00500',
|
33
|
+
'00501', '00502', '00503', '00504', '00505', '00506', '00507',
|
34
|
+
'00508', '00509', '0051', '0052', '0053', '0054', '0055',
|
35
|
+
'0056', '0057', '0058', '00590', '00591', '00592', '00593',
|
36
|
+
'00594', '00595', '00596', '00597', '00598', '00599', '0060',
|
37
|
+
'0061', '0062', '0063', '0064', '0065', '0066', '00670',
|
38
|
+
'00671', '00673', '00674', '00675', '00676', '00677', '00678',
|
39
|
+
'00679', '00680', '00682', '00684', '00685', '00686', '00687',
|
40
|
+
'00689', '00691', '00692', '007', '0081', '0084', '00850',
|
41
|
+
'00852', '00853', '00855', '00856', '0086', '00880', '00886',
|
42
|
+
'0090', '0091', '0092', '0094', '0095', '00960', '00961',
|
43
|
+
'00962', '00963', '00964', '00965', '00966', '00967', '00968',
|
44
|
+
'00971', '00972', '00973', '00974', '00975', '00976', '00977',
|
45
|
+
'0098', '00994' ]
|
46
|
+
def initialize(mobile_number)
|
47
|
+
@mobile_number = mobile_number
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Return the correct mobile number as Class
|
52
|
+
#
|
53
|
+
# @author dmasur
|
54
|
+
def self.get_number number
|
55
|
+
$delete_mobile_numbers ||= []
|
56
|
+
number = new(number).get_number
|
57
|
+
return number
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# Return the correct mobile number
|
62
|
+
#
|
63
|
+
# @author dmasur
|
64
|
+
def get_number
|
65
|
+
org_num = @mobile_number
|
66
|
+
#puts "Full Number: #{@mobile_number}"
|
67
|
+
correct_typos_in_mobile_number
|
68
|
+
#puts "Typofix: #{@mobile_number}"
|
69
|
+
filter_part
|
70
|
+
#puts "After Filter: #{@mobile_number}"
|
71
|
+
clean_mobile_number
|
72
|
+
#puts "After clean: #{@mobile_number}"
|
73
|
+
mobile_number = "" unless has_valid_area_code?
|
74
|
+
$delete_mobile_numbers << org_num if @mobile_number.blank? && !org_num.blank?
|
75
|
+
return @mobile_number
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# Normalize mobile number
|
80
|
+
#
|
81
|
+
# @author dmasur
|
82
|
+
def clean_mobile_number
|
83
|
+
@mobile_number = MobileNumberNormalizer.clean_number @mobile_number
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Try to fix typos in the mobile number
|
88
|
+
#
|
89
|
+
# @author dmasur
|
90
|
+
def correct_typos_in_mobile_number
|
91
|
+
@mobile_number.strip!
|
92
|
+
@mobile_number.gsub!(/[ßo]/, '0')
|
93
|
+
@mobile_number.gsub!(/[\(\)\.]/, '')
|
94
|
+
@mobile_number.gsub!(/\s(\d{2})\s/, '\1')
|
95
|
+
@mobile_number.gsub!(/[a-zA-Z\-]/, '')
|
96
|
+
end
|
97
|
+
|
98
|
+
##
|
99
|
+
# Try to guess the right part of the mobile number
|
100
|
+
#
|
101
|
+
# @author dmasur
|
102
|
+
def filter_part
|
103
|
+
good_guess = nil
|
104
|
+
#puts splits
|
105
|
+
splits.each do |split|
|
106
|
+
good_guess = split if MobileNumberNormalizer.looks_like_a_mobile_number(split.strip)
|
107
|
+
end
|
108
|
+
#puts "Guess: #{good_guess}"
|
109
|
+
@mobile_number = good_guess unless good_guess.blank?
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# Split the number in uniq Parts
|
114
|
+
#
|
115
|
+
# @return [Array] Possible Numbers
|
116
|
+
# @author dmasur
|
117
|
+
def splits
|
118
|
+
split_chars = [/\s/,/\s{2}/, ':', ',', '/', '//', ')', '.', ' 0 ', ';']
|
119
|
+
return split_chars.map { |split_char| @mobile_number.split(split_char) }.flatten.uniq
|
120
|
+
end
|
121
|
+
|
122
|
+
##
|
123
|
+
# Determinate if the number could be a mobile number
|
124
|
+
#
|
125
|
+
# @param [String] number Mobile number
|
126
|
+
# @return [Boolean] is valild number?
|
127
|
+
# @author dmasur
|
128
|
+
def self.looks_like_a_mobile_number number
|
129
|
+
if !number.blank?
|
130
|
+
#puts "Dirty Part: #{number}"
|
131
|
+
clean_number = MobileNumberNormalizer.clean_number(number)
|
132
|
+
#puts "Clean Part: #{number}: #{clean_number}"
|
133
|
+
if !clean_number.blank? && clean_number.length > MIN_MOBILE_NUMBER_LENGTH
|
134
|
+
#puts "Nice Part: #{number}"
|
135
|
+
return /^00491/ =~ clean_number
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
##
|
141
|
+
# Clean a mobile number
|
142
|
+
#
|
143
|
+
# @param [String] mobile_number Mobile Number
|
144
|
+
# @return [String] Mobile Number
|
145
|
+
# @author dmasur
|
146
|
+
def self.clean_number mobile_number
|
147
|
+
mobile_number.strip!
|
148
|
+
mobile_number = replace_prefix mobile_number
|
149
|
+
#puts mobile_number
|
150
|
+
mobile_number = remove_superflouid_chars mobile_number
|
151
|
+
#puts mobile_number
|
152
|
+
mobile_number = "0049#{mobile_number[1..-1]}" if /^0[1-9]/ =~ mobile_number
|
153
|
+
delete_invalid_numbers mobile_number
|
154
|
+
end
|
155
|
+
|
156
|
+
##
|
157
|
+
# Deletes the number if it is invalid
|
158
|
+
#
|
159
|
+
# @param [String] mobile_number Mobile Number
|
160
|
+
# @return [String] Mobile Number
|
161
|
+
# @author dmasur
|
162
|
+
def self.delete_invalid_numbers mobile_number
|
163
|
+
mobile_number = "" unless mobile_number.length.between?(MIN_MOBILE_NUMBER_LENGTH, 20)
|
164
|
+
mobile_number = "" if /^[^0]/ =~ mobile_number
|
165
|
+
return mobile_number
|
166
|
+
end
|
167
|
+
|
168
|
+
def has_valid_area_code?
|
169
|
+
VALID_INTERNATIONAL_AREA_CODE.any? do |area_code|
|
170
|
+
Regexp.new("^#{area_code}") =~ @mobile_number
|
171
|
+
end
|
172
|
+
end
|
173
|
+
##
|
174
|
+
# Replace the different number prefix
|
175
|
+
#
|
176
|
+
# @param [String] mobile_number Mobile Number
|
177
|
+
# @return [String] Mobile Number
|
178
|
+
# @author dmasur
|
179
|
+
def self.replace_prefix mobile_number
|
180
|
+
mobile_number = "0#{mobile_number}" if /^1/ =~ mobile_number
|
181
|
+
mobile_number.sub!(/^49/, '0049')
|
182
|
+
mobile_number.sub!(/\+/, '00')
|
183
|
+
VALID_INTERNATIONAL_AREA_CODE.each do |area_code|
|
184
|
+
if mobile_number.start_with?(area_code[2..-1])
|
185
|
+
mobile_number = "00#{mobile_number}"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
return mobile_number
|
189
|
+
end
|
190
|
+
|
191
|
+
##
|
192
|
+
# Removed support characters in numbers
|
193
|
+
#
|
194
|
+
# @return [String] Mobile *Number*
|
195
|
+
# @author dmasur
|
196
|
+
def self.remove_superflouid_chars mobile_number
|
197
|
+
mobile_number.gsub!(/[\(\)\.:´+*^&]/,'')
|
198
|
+
mobile_number.gsub! /[^0-9]*/, ''
|
199
|
+
end
|
200
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/mobile_number_normalizer/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Dominik Masur"]
|
6
|
+
gem.email = ["dominik.masur@googlemail.com"]
|
7
|
+
gem.description = %q{Normalize mobile Phone Numbers}
|
8
|
+
gem.summary = %q{Normalize mobile Phone Numbers}
|
9
|
+
gem.homepage = "https://github.com/TBAA/mobile_number_normalizer"
|
10
|
+
gem.version = MobileNumberNormalizer::VERSION
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "mobile_number_normalizer"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = MobileNumberNormalizer::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "rspec"
|
19
|
+
gem.add_development_dependency "active_support"
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# All Testcases are derived from real mobile numbers
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../lib/mobile_number_normalizer')
|
4
|
+
require 'active_support/core_ext/object/blank'
|
5
|
+
describe MobileNumberNormalizer do
|
6
|
+
|
7
|
+
describe "should parse number" do
|
8
|
+
it "without international area prefix" do
|
9
|
+
MobileNumberNormalizer.get_number("01771234567").should == "00491771234567"
|
10
|
+
end
|
11
|
+
it "with + in front as 00" do
|
12
|
+
MobileNumberNormalizer.get_number("+49 1771234567").should == "00491771234567"
|
13
|
+
end
|
14
|
+
it "with space in it" do
|
15
|
+
MobileNumberNormalizer.get_number("01520 1234567").should == "004915201234567"
|
16
|
+
end
|
17
|
+
it "without 00 of international prefix" do
|
18
|
+
MobileNumberNormalizer.get_number("321234567").should == "00321234567"
|
19
|
+
end
|
20
|
+
it "with , sperated" do
|
21
|
+
MobileNumberNormalizer.get_number("0049176-12345678,0178-1234567").should == "00491781234567"
|
22
|
+
end
|
23
|
+
it "with / in the number" do
|
24
|
+
MobileNumberNormalizer.get_number("0049177/1234567").should == "00491771234567"
|
25
|
+
end
|
26
|
+
it "with ß as 0 in the end (german typo)" do
|
27
|
+
MobileNumberNormalizer.get_number("0049178123456ß").should == "00491781234560"
|
28
|
+
end
|
29
|
+
it "with ß as 0 at front (german typo)" do
|
30
|
+
MobileNumberNormalizer.get_number("ß1761234567").should == "00491761234567"
|
31
|
+
end
|
32
|
+
it "0 to blank" do
|
33
|
+
MobileNumberNormalizer.get_number("0").should be_blank
|
34
|
+
end
|
35
|
+
it "00000000000000000000000000000000000 to blank" do
|
36
|
+
MobileNumberNormalizer.get_number("00000000000000000000000000000000000").should be_blank
|
37
|
+
end
|
38
|
+
it "with prefix in () and first number is a 9" do
|
39
|
+
MobileNumberNormalizer.get_number("(0160) 923 456 78 ").should == "004916092345678"
|
40
|
+
end
|
41
|
+
it "with prefix in () and first number is a 1" do
|
42
|
+
MobileNumberNormalizer.get_number("(0160) 123 456 78 ").should == "004916012345678"
|
43
|
+
end
|
44
|
+
it "with . in the middle and first number is a 9" do
|
45
|
+
MobileNumberNormalizer.get_number("0049176.92345678").should == "004917692345678"
|
46
|
+
end
|
47
|
+
it "with . in the middle and first number is a 1" do
|
48
|
+
MobileNumberNormalizer.get_number("0049176.12345678").should == "004917612345678"
|
49
|
+
end
|
50
|
+
it "with a Tel string in the middle of two numbers" do
|
51
|
+
MobileNumberNormalizer.get_number("017746 12345 Tel: 0221 1234567").
|
52
|
+
should == "00491774612345"
|
53
|
+
end
|
54
|
+
it "with a prefix of Mobil:" do
|
55
|
+
MobileNumberNormalizer.get_number(" Mobil:015712345678 ").should == "004915712345678"
|
56
|
+
end
|
57
|
+
it "with a - in the middle and spaces between numbers" do
|
58
|
+
MobileNumberNormalizer.get_number(" 0172 - 12 345 67").should == "00491721234567"
|
59
|
+
end
|
60
|
+
it "with a ´ in the middle" do
|
61
|
+
MobileNumberNormalizer.get_number("004917´12345678").should == "00491712345678"
|
62
|
+
end
|
63
|
+
it "with a o as 0" do
|
64
|
+
MobileNumberNormalizer.get_number("o1721234567").should == "00491721234567"
|
65
|
+
end
|
66
|
+
it "without a 0 at front" do
|
67
|
+
MobileNumberNormalizer.get_number("163/1234567").should == "00491631234567"
|
68
|
+
end
|
69
|
+
it "with two ++ in the front" do
|
70
|
+
MobileNumberNormalizer.get_number("++491601234567").should == "00491601234567"
|
71
|
+
end
|
72
|
+
it "with * in it to blank" do
|
73
|
+
MobileNumberNormalizer.get_number("0049176******").should == ""
|
74
|
+
end
|
75
|
+
it "with a ^ at the end" do
|
76
|
+
MobileNumberNormalizer.get_number("004915212345678^").should == "004915212345678"
|
77
|
+
end
|
78
|
+
it "with a & in the middle" do
|
79
|
+
MobileNumberNormalizer.get_number("0049162&1234567").should == "00491621234567"
|
80
|
+
end
|
81
|
+
it "without 00 in the area prefix" do
|
82
|
+
MobileNumberNormalizer.get_number("49 1 768 123 4567").should == "004917681234567"
|
83
|
+
end
|
84
|
+
it "with a prefix that is seperated with /" do
|
85
|
+
MobileNumberNormalizer.get_number("/0157/ 923-456-78").should == "004915792345678"
|
86
|
+
end
|
87
|
+
xit "with a prefix that is seperated with / and a number starting with 1" do
|
88
|
+
MobileNumberNormalizer.get_number("/0157/ 123-456-78").should == "004915712345678"
|
89
|
+
end
|
90
|
+
it "with %§$= to blank" do
|
91
|
+
MobileNumberNormalizer.get_number("0049173%§$=").should == ""
|
92
|
+
end
|
93
|
+
it "with numbers seperated with spaces" do
|
94
|
+
MobileNumberNormalizer.get_number("+44 742 123 4567").should == "00447421234567"
|
95
|
+
end
|
96
|
+
it "with two numbers sperated by / " do
|
97
|
+
MobileNumberNormalizer.get_number("015771234567 / 0031611234567").should == "004915771234567"
|
98
|
+
end
|
99
|
+
it "with one number in ()" do
|
100
|
+
input = "0177-1234567 (001-123-456-7890)"
|
101
|
+
MobileNumberNormalizer.get_number(input).should == "00491771234567"
|
102
|
+
end
|
103
|
+
it "with many spaces in the middle" do
|
104
|
+
MobileNumberNormalizer.get_number("030/ 123 45 67 (0176 1234567)").
|
105
|
+
should == "00491761234567"
|
106
|
+
end
|
107
|
+
it "with prefox Mobil Nr." do
|
108
|
+
MobileNumberNormalizer.get_number("Mobil Nr. 0177-1234567").should == "00491771234567"
|
109
|
+
end
|
110
|
+
it "with two numbers sperated by space" do
|
111
|
+
MobileNumberNormalizer.get_number("06131-1234567 0174-1234567").should == "00491741234567"
|
112
|
+
end
|
113
|
+
it "with two prefixed numbers" do
|
114
|
+
MobileNumberNormalizer.get_number("Handy: 01731234567 Tel.: 1234567").
|
115
|
+
should == "00491731234567"
|
116
|
+
end
|
117
|
+
it "with two numbers sperated by /" do
|
118
|
+
MobileNumberNormalizer.get_number("0049 1631234567 / 0031 123456789").
|
119
|
+
should == "00491631234567"
|
120
|
+
end
|
121
|
+
it "with two numbers sperated by / and spaces" do
|
122
|
+
MobileNumberNormalizer.get_number("030 123 456 78 / 0162 123 4567").should == "00491621234567"
|
123
|
+
end
|
124
|
+
it "with two numbers sperated by /" do
|
125
|
+
MobileNumberNormalizer.get_number("015212345678 / 017612345678").should == "004917612345678"
|
126
|
+
end
|
127
|
+
it "with two numbers sperated by 0" do
|
128
|
+
MobileNumberNormalizer.get_number("030 12345678 0 0176 12345678").should == "004917612345678"
|
129
|
+
end
|
130
|
+
it "with a area prefix in ()" do
|
131
|
+
MobileNumberNormalizer.get_number("(+49)176-12345678").should == "004917612345678"
|
132
|
+
end
|
133
|
+
it "with two numbers and postfixes in ()" do
|
134
|
+
MobileNumberNormalizer.get_number("+493012345678 () / +4915712345678 (0)").
|
135
|
+
should == "0049157123456780"
|
136
|
+
end
|
137
|
+
it "with three numbers seperated by //" do
|
138
|
+
MobileNumberNormalizer.get_number("0221/1234567 // 0160/12345678//0151/12345678").
|
139
|
+
should == "004915112345678"
|
140
|
+
end
|
141
|
+
it "with a /[:space:] in it" do
|
142
|
+
MobileNumberNormalizer.get_number("0049/ 17612345678").
|
143
|
+
should == "004917612345678"
|
144
|
+
end
|
145
|
+
it "with two numbers and a ) at the end" do
|
146
|
+
MobileNumberNormalizer.get_number("02323 123456 ) 0173 1234567 )").
|
147
|
+
should == "00491731234567"
|
148
|
+
end
|
149
|
+
it "without 00 at the beginning of area prefix" do
|
150
|
+
MobileNumberNormalizer.get_number("420771234567").
|
151
|
+
should == "00420771234567"
|
152
|
+
end
|
153
|
+
it "with two numbers seperated by a ." do
|
154
|
+
MobileNumberNormalizer.get_number("02233 / 923456 . 0172 / 9234567").
|
155
|
+
should == "00491729234567"
|
156
|
+
end
|
157
|
+
xit "with two numbers seperated by a ." do
|
158
|
+
MobileNumberNormalizer.get_number("02233 / 123456 . 0172 / 1234567").
|
159
|
+
should == "00491721234567"
|
160
|
+
end
|
161
|
+
it "with two numbers seperated by a 0" do
|
162
|
+
MobileNumberNormalizer.get_number("0531 1234567 0 0173 1234567").
|
163
|
+
should == "00491731234567"
|
164
|
+
end
|
165
|
+
it "with two numbers seperated by a ;" do
|
166
|
+
MobileNumberNormalizer.get_number("0049 176 12345678; 0043 6712345678").
|
167
|
+
should == "004917612345678"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
describe "area codes" do
|
171
|
+
it "should accept right area code" do
|
172
|
+
MobileNumberNormalizer.get_number("0018091234567111").should == "0018091234567111"
|
173
|
+
end
|
174
|
+
it "should reject wrong area code" do
|
175
|
+
MobileNumberNormalizer.get_number("0018091234567111").should == "0018091234567111"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mobile_number_normalizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dominik Masur
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-04-29 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: active_support
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
description: Normalize mobile Phone Numbers
|
63
|
+
email:
|
64
|
+
- dominik.masur@googlemail.com
|
65
|
+
executables: []
|
66
|
+
|
67
|
+
extensions: []
|
68
|
+
|
69
|
+
extra_rdoc_files: []
|
70
|
+
|
71
|
+
files:
|
72
|
+
- .gitignore
|
73
|
+
- .rspec
|
74
|
+
- .travis.yml
|
75
|
+
- CHANGELOG.md
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/mobile_number_normalizer.rb
|
81
|
+
- lib/mobile_number_normalizer/version.rb
|
82
|
+
- mobile_number_normalizer.gemspec
|
83
|
+
- spec/lib/mobile_number_normalizer_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
homepage: https://github.com/TBAA/mobile_number_normalizer
|
86
|
+
licenses: []
|
87
|
+
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
requirements: []
|
112
|
+
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.8.10
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Normalize mobile Phone Numbers
|
118
|
+
test_files:
|
119
|
+
- spec/lib/mobile_number_normalizer_spec.rb
|
120
|
+
- spec/spec_helper.rb
|