polish_cell_number_checker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in polish_cell_number_checker.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Damian Baćkowski
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.
@@ -0,0 +1,27 @@
1
+ # PolishCellNumberChecker
2
+
3
+ Checks if phone number is cell number and get GSM operator name.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'polish_cell_number_checker'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install polish_cell_number_checker
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ p = PolishCellNumber::Checker.new('+48 608-111-111')
23
+ p.cell_number? => true
24
+ p.operator_name => "PTC S.A."
25
+ ```
26
+
27
+ Copyright (c) 2012 [Damian Baćkowski], released under the MIT license
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
8
+ task :test => :spec
@@ -0,0 +1,34 @@
1
+ require "polish_cell_number_checker/version"
2
+ require 'yaml'
3
+
4
+ module PolishCellNumber
5
+ class Checker
6
+ private
7
+ def load_data
8
+ @@data ||= YAML.load_file(File.join(File.dirname(__FILE__), '../yaml/operators.yml'))
9
+ end
10
+
11
+ def check_number
12
+ @found = @phone_no =~ /[0-9]{9}/ ? @@data.select { |_, pool| pool.find { |e| @phone_no =~ /^#{e}/ } } : []
13
+ end
14
+
15
+ public
16
+ def initialize(phone_no)
17
+ @phone_no = phone_no
18
+
19
+ @phone_no.gsub!(/\D/, '')
20
+ @phone_no.gsub!(/^48/, '')
21
+
22
+ load_data
23
+ check_number
24
+ end
25
+
26
+ def cell_number?
27
+ !@found.empty?
28
+ end
29
+
30
+ def operator_name
31
+ @found[0][0] unless @found.empty?
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module PolishCellNumberChecker
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/polish_cell_number_checker/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Damian Ba\304\207kowski"]
6
+ gem.email = ["damianbackowski@gmail.com"]
7
+ gem.description = %q{Provide polish cell number check}
8
+ gem.summary = %q{Provide check when phone number is polish cell number, get operator name}
9
+ gem.homepage = "https://github.com/dbackowski/polish_cell_number_checker"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "polish_cell_number_checker"
15
+ gem.require_paths = ["lib", "yaml"]
16
+ gem.version = PolishCellNumberChecker::VERSION
17
+
18
+ gem.add_development_dependency 'rake'
19
+ gem.add_development_dependency 'rspec'
20
+ end
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+ require 'yaml'
4
+
5
+ # http://www.uke.gov.pl/tablice/home.do?execution=e1s1 download xml file
6
+
7
+ data = {}
8
+ doc = Nokogiri::XML.parse(File.read(ARGV[0]))
9
+
10
+ doc.xpath('//numery/plmn').each do |node|
11
+ number = node.xpath('numer').inner_text
12
+ operator = node.xpath('operator').inner_text
13
+
14
+ m = number.match /([0-9]+)\(([0-9,-]+)\)/
15
+ numbers = []
16
+
17
+ data[operator] = [] unless data.has_key?(operator)
18
+
19
+ if m
20
+ number = m[1]
21
+ m[2].split(',').each do |i|
22
+ range = i.split('-')
23
+
24
+ if range.length > 1
25
+ Range.new(range[0].to_i,range[1].to_i == 0 ? 10 : range[1].to_i).each do |i|
26
+ numbers.push "#{number}#{i == 10 ? 0 : i}"
27
+ end
28
+ else
29
+ numbers.push "#{number}#{i}"
30
+ end
31
+ end
32
+
33
+ data[operator].push numbers
34
+ data[operator].flatten!(1)
35
+ else
36
+ data[operator].push number
37
+ end
38
+ end
39
+
40
+ File.open("yaml/operators.yml", "w") do |file|
41
+ file.write data.to_yaml
42
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe PolishCellNumber::Checker do
4
+ describe ".cell_number?" do
5
+ context "when passing number is cell number" do
6
+ it "return true" do
7
+ PolishCellNumber::Checker.new('+48 608-111-111').cell_number?.should be_true
8
+ end
9
+ end
10
+
11
+ context "when passing number is not cell number" do
12
+ it "return false" do
13
+ PolishCellNumber::Checker.new('+48 751-11-111').cell_number?.should_not be_true
14
+ end
15
+ end
16
+
17
+ context "when passing number is not valid number" do
18
+ it "return false" do
19
+ PolishCellNumber::Checker.new('+48 751-11').cell_number?.should_not be_true
20
+ end
21
+ end
22
+ end
23
+
24
+ describe ".operator_name" do
25
+ context "when passing number is cell number" do
26
+ it "return operator name" do
27
+ PolishCellNumber::Checker.new('+48 608-111-111').operator_name.should eql 'PTC S.A.'
28
+ end
29
+ end
30
+
31
+ context "when passing number is not cell number" do
32
+ it "return nil" do
33
+ PolishCellNumber::Checker.new('+48 751-11-111').operator_name.should be_nil
34
+ end
35
+ end
36
+
37
+ context "when passing number is not valid number" do
38
+ it "return nil" do
39
+ PolishCellNumber::Checker.new('+48 751-11').operator_name.should be_nil
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1 @@
1
+ require 'polish_cell_number_checker'
@@ -0,0 +1,326 @@
1
+ ---
2
+ Rezerwa Prezesa UKE:
3
+ - "72975"
4
+ - "72976"
5
+ - "72977"
6
+ - "72978"
7
+ - "72979"
8
+ MASSPAY S.A.:
9
+ - "69979"
10
+ MoSoCo Sp. z o.o.:
11
+ - "69960"
12
+ PTC S.A.:
13
+ - "532"
14
+ - "538"
15
+ - "539"
16
+ - "600"
17
+ - "602"
18
+ - "604"
19
+ - "606"
20
+ - "608"
21
+ - "660"
22
+ - "662"
23
+ - "664"
24
+ - "6661"
25
+ - "6662"
26
+ - "6663"
27
+ - "6664"
28
+ - "6665"
29
+ - "6667"
30
+ - "6668"
31
+ - "6669"
32
+ - "6660"
33
+ - "668"
34
+ - "692"
35
+ - "694"
36
+ - "696"
37
+ - "698"
38
+ - "7272"
39
+ - "7273"
40
+ - "7281"
41
+ - "7282"
42
+ - "7283"
43
+ - "7284"
44
+ - "7285"
45
+ - "7286"
46
+ - "7287"
47
+ - "7288"
48
+ - "7289"
49
+ - "784"
50
+ - "787"
51
+ - "788"
52
+ - "7951"
53
+ - "7952"
54
+ - "7953"
55
+ - "7954"
56
+ - "7955"
57
+ - "880"
58
+ - "8818"
59
+ - "8819"
60
+ - "8810"
61
+ - "882"
62
+ - "8833"
63
+ - "8838"
64
+ - "8841"
65
+ - "8842"
66
+ - "886"
67
+ - "888"
68
+ - "889"
69
+ NEXTGEN MOBILE LTD:
70
+ - "72973"
71
+ - "72974"
72
+ Cyfrowy POLSAT S.A.:
73
+ - "69900"
74
+ - "69902"
75
+ - "69903"
76
+ - "69904"
77
+ - "69905"
78
+ - "69906"
79
+ - "69907"
80
+ - "69908"
81
+ - "69909"
82
+ - "69910"
83
+ - "69911"
84
+ - "69912"
85
+ - "69913"
86
+ - "69914"
87
+ - "69915"
88
+ - "69916"
89
+ - "69917"
90
+ - "69918"
91
+ - "69919"
92
+ - "69920"
93
+ - "69921"
94
+ - "69923"
95
+ - "69924"
96
+ - "69925"
97
+ - "69926"
98
+ - "69927"
99
+ - "69928"
100
+ - "69929"
101
+ - "6993"
102
+ - "6994"
103
+ - "69961"
104
+ - "69962"
105
+ - "69963"
106
+ - "69964"
107
+ - "69965"
108
+ - "69966"
109
+ - "69968"
110
+ AERO 2 Sp. z o.o.:
111
+ - "8844"
112
+ MOBYLAND Sp. z o.o.:
113
+ - "7280"
114
+ MPAY S.A.:
115
+ - "69967"
116
+ - "69969"
117
+ CenterNet S.A.:
118
+ - "6907"
119
+ - "7201"
120
+ - "7202"
121
+ - "7203"
122
+ - "7204"
123
+ - "7205"
124
+ - "7206"
125
+ - "7207"
126
+ - "7209"
127
+ - "7200"
128
+ - "8811"
129
+ AMD Telecom S.A.:
130
+ - "69901"
131
+ - "69950"
132
+ - "72970"
133
+ PTK Centertel Sp. z o.o.:
134
+ - "500"
135
+ - "501"
136
+ - "502"
137
+ - "503"
138
+ - "504"
139
+ - "505"
140
+ - "506"
141
+ - "507"
142
+ - "508"
143
+ - "509"
144
+ - "510"
145
+ - "511"
146
+ - "512"
147
+ - "513"
148
+ - "514"
149
+ - "515"
150
+ - "516"
151
+ - "517"
152
+ - "518"
153
+ - "519"
154
+ - "6901"
155
+ - "6902"
156
+ - "6903"
157
+ - "6904"
158
+ - "6905"
159
+ - "6906"
160
+ - "780"
161
+ - "7865"
162
+ - "7866"
163
+ - "7867"
164
+ - "7868"
165
+ - "7869"
166
+ - "7890"
167
+ - "7891"
168
+ - "7892"
169
+ - "7893"
170
+ - "7894"
171
+ - "797"
172
+ - "798"
173
+ - "7990"
174
+ - "7996"
175
+ - "7997"
176
+ - "7998"
177
+ - "7999"
178
+ MNI Mobile S.A.:
179
+ - "7860"
180
+ - "7863"
181
+ Vectra S.A.:
182
+ - "73930"
183
+ PKP Polskie Linie Kolejowe S.A.:
184
+ - "738"
185
+ Polskie Sieci Cyfrowe Sp. z o.o.:
186
+ - "5366"
187
+ P4 Sp. z o.o.:
188
+ - "530"
189
+ - "531"
190
+ - "533"
191
+ - "534"
192
+ - "535"
193
+ - "5361"
194
+ - "5362"
195
+ - "5363"
196
+ - "5364"
197
+ - "5365"
198
+ - "5367"
199
+ - "5368"
200
+ - "5369"
201
+ - "5360"
202
+ - "537"
203
+ - "6666"
204
+ - "6908"
205
+ - "6909"
206
+ - "6900"
207
+ - "7208"
208
+ - "7290"
209
+ - "7291"
210
+ - "730"
211
+ - "731"
212
+ - "733"
213
+ - "7392"
214
+ - "7390"
215
+ - "7861"
216
+ - "7862"
217
+ - "790"
218
+ - "791"
219
+ - "792"
220
+ - "793"
221
+ - "794"
222
+ - "7956"
223
+ - "7957"
224
+ - "7958"
225
+ - "7959"
226
+ - "7950"
227
+ - "796"
228
+ - "7991"
229
+ - "7992"
230
+ - "7993"
231
+ - "7994"
232
+ - "7995"
233
+ - "8812"
234
+ - "8813"
235
+ - "8814"
236
+ - "8815"
237
+ - "8816"
238
+ - "8817"
239
+ - "8831"
240
+ - "8832"
241
+ - "8834"
242
+ - "8835"
243
+ - "8836"
244
+ - "8837"
245
+ - "8839"
246
+ - "8830"
247
+ - "8843"
248
+ - "8846"
249
+ - "8847"
250
+ - "8848"
251
+ - "8849"
252
+ - "8840"
253
+ SFERIA S.A.:
254
+ - "8845"
255
+ Nordisk Polska Sp. z o.o.:
256
+ - "7271"
257
+ COMPATEL LIMITED:
258
+ - "69974"
259
+ - "72972"
260
+ Teleena Holding BV:
261
+ - "69951"
262
+ - "69952"
263
+ - "69953"
264
+ - "69954"
265
+ - "69955"
266
+ - "69956"
267
+ - "69957"
268
+ - "69958"
269
+ - "69959"
270
+ - "69971"
271
+ Lycamobile Sp. z o.o.:
272
+ - "7292"
273
+ - "7293"
274
+ - "7294"
275
+ - "7295"
276
+ - "7296"
277
+ E-Telko Sp. z o.o.:
278
+ - "69922"
279
+ Polkomtel Sp. z o.o.:
280
+ - "601"
281
+ - "603"
282
+ - "605"
283
+ - "607"
284
+ - "609"
285
+ - "661"
286
+ - "663"
287
+ - "665"
288
+ - "667"
289
+ - "669"
290
+ - "691"
291
+ - "693"
292
+ - "695"
293
+ - "697"
294
+ - "721"
295
+ - "722"
296
+ - "723"
297
+ - "724"
298
+ - "725"
299
+ - "726"
300
+ - "7274"
301
+ - "7275"
302
+ - "7276"
303
+ - "7277"
304
+ - "7278"
305
+ - "7279"
306
+ - "7270"
307
+ - "781"
308
+ - "782"
309
+ - "783"
310
+ - "785"
311
+ - "7895"
312
+ - "7896"
313
+ - "7897"
314
+ - "7898"
315
+ - "7899"
316
+ - "885"
317
+ - "887"
318
+ Mundio Mobile Sp. z o.o.:
319
+ - "7298"
320
+ - "7299"
321
+ - "7391"
322
+ "Sat Film Sp. z o.o. i Wsp\xC3\xB3lnicy Sp.k.":
323
+ - "72971"
324
+ Telefonia Dialog Sp. z o.o.:
325
+ - "6998"
326
+ - "6999"
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: polish_cell_number_checker
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
+ - "Damian Ba\xC4\x87kowski"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-10-31 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
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: rspec
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
+ description: Provide polish cell number check
49
+ email:
50
+ - damianbackowski@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - .rspec
60
+ - Gemfile
61
+ - LICENSE
62
+ - README.md
63
+ - Rakefile
64
+ - lib/polish_cell_number_checker.rb
65
+ - lib/polish_cell_number_checker/version.rb
66
+ - polish_cell_number_checker.gemspec
67
+ - script/operators_data_parser.rb
68
+ - spec/polish_cell_number_checker_spec.rb
69
+ - spec/spec_helper.rb
70
+ - yaml/operators.yml
71
+ homepage: https://github.com/dbackowski/polish_cell_number_checker
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options: []
76
+
77
+ require_paths:
78
+ - lib
79
+ - yaml
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.10
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Provide check when phone number is polish cell number, get operator name
105
+ test_files: []
106
+