sanitized_msisdns 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.
- checksums.yaml +15 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/Guardfile +5 -0
- data/README.md +1 -0
- data/lib/msisdn-sanitizer/errors.rb +11 -0
- data/lib/msisdn-sanitizer/sanitizer.rb +67 -0
- data/lib/msisdn-sanitizer/version.rb +5 -0
- data/lib/msisdn_sanitizer.rb +6 -0
- data/sanitized_msisdns.gemspec +29 -0
- data/spec/sanitizer_spec.rb +108 -0
- data/spec/spec_helper.rb +8 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YjE4ODhjNWRmMzZlYTIxMGI2MGU2MGI0N2ZjZWE1Nzc1Zjk4NTYzYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjVkMTFmZGIzYjZkYzQ5YjRiZTRhZjMwZGI5YWYzMTdkY2ViNzZjYg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
M2JkMjdhM2QzMWUyMjNiYjM2YjQ2NGM5NzllMGJhOTkxZGVmMmRmMmM5MzZm
|
10
|
+
N2Q4NzZjNmZhMDliOTE2NTFkZWQxNzdjM2NlZDNiNGM5MjhjMjc0OTY5MjM3
|
11
|
+
NTQyZTM3ODkwZmNlMmRhZTllYmUzNjI3ZDBkNTkwN2NlMjJkMjI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTkwMzFmMmFlODIzZGNlZDc2NTZiZWYwOWRiOTg4NzM2YjU3MTI5NGNhMTU5
|
14
|
+
NjA3MWJjYTNjZmNiNGMyZGI2OTVkMDgwOGJiMTc4ZDJiMjRlMDM0ZTRkYTI0
|
15
|
+
ZjIzYTMxZmM2MWZhNWQ5MGQyYjNhMzcxNDNmNzc3NGJjZTg3OTg=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
A small gem to sanitize MSISDNS as per mobile Number format. This is specially useful for building apis for Android or Iphone apps where the MSISDN is stored in different formats. Currently only indian numbers are supported.
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module MSISDN
|
2
|
+
class Sanitizer
|
3
|
+
|
4
|
+
# Sanitizes the msisdns
|
5
|
+
# @author Sunil Kumar <sunikumar.gec56@gmail.com>
|
6
|
+
# @param [Array, String] supports msisdn or a list of msisdns.
|
7
|
+
# @param [Hash] options specifying format & country code.
|
8
|
+
# @return [Array] list of sanitized msisdns.
|
9
|
+
|
10
|
+
|
11
|
+
ALLOWED_CODES = {in: %w(0091 +91 0)}
|
12
|
+
MSISDN_LENGTH = {in: 10}
|
13
|
+
ALLOWED_FORMATS = %w( local international )
|
14
|
+
CLEANUP_REGEX = /[^0-9A-Za-z+]/
|
15
|
+
|
16
|
+
class << self
|
17
|
+
|
18
|
+
def sanitize(msisdns, options = {})
|
19
|
+
options.reverse_merge!(
|
20
|
+
:country_code => :in,
|
21
|
+
:format => 'international'
|
22
|
+
)
|
23
|
+
|
24
|
+
raise(InvalidArgumentTypeException, 'Argument must be a string, fixnum or an array.') unless [String, Array, Fixnum].include? msisdns.class
|
25
|
+
raise(InvalidFormatException, 'Invalid format passed as option.') unless ALLOWED_FORMATS.include? options[:format]
|
26
|
+
raise(InvalidCountryCodeException, 'Invalid country code passed as option.') unless ALLOWED_CODES.keys.include? options[:country_code]
|
27
|
+
|
28
|
+
msisdn_list =
|
29
|
+
case msisdns
|
30
|
+
when Array
|
31
|
+
msisdns.collect {|msisdn| msisdn.to_s}
|
32
|
+
when String
|
33
|
+
[msisdns]
|
34
|
+
when Fixnum
|
35
|
+
[msisdns.to_s]
|
36
|
+
end
|
37
|
+
|
38
|
+
filtered_list = clean_and_filter(msisdn_list, options[:country_code])
|
39
|
+
standardize(filtered_list, options[:format])
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def clean_and_filter(msisdn_list, country_code)
|
45
|
+
filtered_list = msisdn_list.collect do |msisdn|
|
46
|
+
cleaned_msisdn = msisdn.gsub(CLEANUP_REGEX, '')
|
47
|
+
next unless cleaned_msisdn
|
48
|
+
last_ten_digits = cleaned_msisdn.slice(-MSISDN_LENGTH[country_code]..-1)
|
49
|
+
next unless last_ten_digits
|
50
|
+
prefix_code = cleaned_msisdn.slice(0..(-MSISDN_LENGTH[country_code]-1))
|
51
|
+
(ALLOWED_CODES[country_code] << '').include?(prefix_code) ? last_ten_digits : nil
|
52
|
+
end
|
53
|
+
filtered_list.compact
|
54
|
+
end
|
55
|
+
|
56
|
+
def standardize(filtered_list, format)
|
57
|
+
standardized_list = if format == 'international'
|
58
|
+
filtered_list.collect { |msisdn| msisdn.msisdn(format: 'plus_country') }
|
59
|
+
else
|
60
|
+
filtered_list.collect { |msisdn| msisdn.msisdn(format: 'local') }
|
61
|
+
end
|
62
|
+
standardized_list.compact
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
lib = File.expand_path('../lib/', __FILE__)
|
2
|
+
$:.unshift lib unless $:.include?(lib)
|
3
|
+
|
4
|
+
require 'msisdn-sanitizer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'sanitized_msisdns'
|
8
|
+
s.version = MSISDN.version
|
9
|
+
s.author = 'Sunil Kumar'
|
10
|
+
s.email = 'sunilkumar.gec56@gmail.com'
|
11
|
+
s.homepage = 'http://tech.sunilnkumar.com/'
|
12
|
+
s.summary = %q{Sanitizes msisdns}
|
13
|
+
s.description = %q{Sanitized the msisdns. Helpful for proper formating of Android mobile numbers. }
|
14
|
+
|
15
|
+
s.add_dependency 'mobme_support'
|
16
|
+
|
17
|
+
s.add_development_dependency 'rspec'
|
18
|
+
s.add_development_dependency 'rake'
|
19
|
+
s.add_development_dependency 'guard'
|
20
|
+
s.add_development_dependency 'guard-rspec'
|
21
|
+
s.add_development_dependency 'simplecov'
|
22
|
+
s.add_development_dependency 'yard'
|
23
|
+
s.add_development_dependency 'simplecov-rcov'
|
24
|
+
s.add_development_dependency 'rdiscount'
|
25
|
+
|
26
|
+
s.files = `git ls-files`.split("\n") - %w(Gemfile.lock .ruby-version)
|
27
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
28
|
+
s.require_paths = %w(lib)
|
29
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/msisdn_sanitizer'
|
3
|
+
|
4
|
+
describe MSISDN::Sanitizer do
|
5
|
+
|
6
|
+
subject { MSISDN::Sanitizer }
|
7
|
+
|
8
|
+
let(:msisdn_list) do
|
9
|
+
[
|
10
|
+
'+918089106942',
|
11
|
+
'8089129856',
|
12
|
+
'09846752687',
|
13
|
+
'00919745044399',
|
14
|
+
'67809123456',
|
15
|
+
'0939-109456',
|
16
|
+
'+91 91 67 100865',
|
17
|
+
'914712438548',
|
18
|
+
'914712',
|
19
|
+
'918891598095',
|
20
|
+
'09539368042',
|
21
|
+
'0041796704934',
|
22
|
+
'+8891090909'
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:filtered_msisdn_list) do
|
27
|
+
%w(
|
28
|
+
8089106942
|
29
|
+
8089129856
|
30
|
+
9846752687
|
31
|
+
9745044399
|
32
|
+
0939109456
|
33
|
+
9167100865
|
34
|
+
9539368042
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:standardized_msisdn_list) do
|
39
|
+
{
|
40
|
+
international_format:
|
41
|
+
%w(
|
42
|
+
+918089106942
|
43
|
+
+918089129856
|
44
|
+
+919846752687
|
45
|
+
+919745044399
|
46
|
+
+919167100865
|
47
|
+
+919539368042
|
48
|
+
),
|
49
|
+
|
50
|
+
local_format:
|
51
|
+
%w(
|
52
|
+
8089106942
|
53
|
+
8089129856
|
54
|
+
9846752687
|
55
|
+
9745044399
|
56
|
+
9167100865
|
57
|
+
9539368042
|
58
|
+
)
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'cleans and filters msisdns by removing all characters which are not digits and +' do
|
63
|
+
expect(subject.send(:clean_and_filter, msisdn_list, :in)).to eq filtered_msisdn_list
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'standardizes the msisdn as per the format provided' do
|
67
|
+
expect(subject.send(:standardize, filtered_msisdn_list, 'local')).to eq standardized_msisdn_list[:local_format]
|
68
|
+
expect(subject.send(:standardize, filtered_msisdn_list, 'international')).to eq standardized_msisdn_list[:international_format]
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'raises an exception if the msisdn passed in not a string or array' do
|
72
|
+
expect{ subject.sanitize( {msisdn: 9897090909} ) }.to raise_error InvalidArgumentTypeException
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'raises an exception if the format provided is not local or international' do
|
76
|
+
expect{ subject.sanitize('9897090909', format: 'regional' ) }.to raise_error InvalidFormatException
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'raises an exception if the country code passed is not in the list of country codes' do
|
80
|
+
expect{ subject.sanitize(['9897090909'], country_code: 'ne' ) }.to raise_error InvalidCountryCodeException
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'uses the default options of format and country code if no other options are given' do
|
84
|
+
subject.should_receive(:clean_and_filter).with(['9897090909'], :in).and_return([])
|
85
|
+
subject.should_receive(:standardize).with([], 'international').and_return([])
|
86
|
+
subject.sanitize(['9897090909'])
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'uses the format and country code if supplied as arguments' do
|
90
|
+
subject.should_receive(:clean_and_filter).with(['9897090909'], :in).and_return([])
|
91
|
+
subject.should_receive(:standardize).with([], 'local').and_return([])
|
92
|
+
subject.sanitize(['9897090909'], format: 'local', country_code: :in)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'converts any arguments into a string of arrays' do
|
96
|
+
subject.stub(:standardize)
|
97
|
+
subject.should_receive(:clean_and_filter).exactly(4).times.with(['9897090909'], :in)
|
98
|
+
subject.sanitize(['9897090909'], format: 'local')
|
99
|
+
subject.sanitize('9897090909', format: 'local')
|
100
|
+
subject.sanitize(9897090909, format: 'local')
|
101
|
+
subject.sanitize([9897090909], format: 'local')
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'returns an array of sanitized msisdns' do
|
105
|
+
expect(subject.sanitize( ['9897090909'], format: 'local') ).to be_a_kind_of(Array)
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sanitized_msisdns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sunil Kumar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mobme_support
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov-rcov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rdiscount
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: ! 'Sanitized the msisdns. Helpful for proper formating of Android mobile
|
140
|
+
numbers. '
|
141
|
+
email: sunilkumar.gec56@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- .gitignore
|
147
|
+
- .rspec
|
148
|
+
- Gemfile
|
149
|
+
- Guardfile
|
150
|
+
- README.md
|
151
|
+
- lib/msisdn-sanitizer/errors.rb
|
152
|
+
- lib/msisdn-sanitizer/sanitizer.rb
|
153
|
+
- lib/msisdn-sanitizer/version.rb
|
154
|
+
- lib/msisdn_sanitizer.rb
|
155
|
+
- sanitized_msisdns.gemspec
|
156
|
+
- spec/sanitizer_spec.rb
|
157
|
+
- spec/spec_helper.rb
|
158
|
+
homepage: http://tech.sunilnkumar.com/
|
159
|
+
licenses: []
|
160
|
+
metadata: {}
|
161
|
+
post_install_message:
|
162
|
+
rdoc_options: []
|
163
|
+
require_paths:
|
164
|
+
- lib
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ! '>='
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ! '>='
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
requirements: []
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 2.1.11
|
178
|
+
signing_key:
|
179
|
+
specification_version: 4
|
180
|
+
summary: Sanitizes msisdns
|
181
|
+
test_files: []
|