will_it_dial 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.markdown +26 -0
- data/Rakefile +53 -0
- data/lib/will_it_dial.rb +97 -0
- data/spec/will_it_dial_us_spec.rb +33 -0
- metadata +72 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Mark Percival
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Will It Dial
|
2
|
+
|
3
|
+
A simple customer phone number validator for lead validation. It's pretty paranoid and will not allow numbers that seem highly unlikely but are technically valid.
|
4
|
+
|
5
|
+
WillItDial::US.check('404-514-6858') => true
|
6
|
+
WillItDial::US.check('1-404-514-6858') => true
|
7
|
+
WillItDial::US.check('404-555-5555') => false # Suspcious
|
8
|
+
WillItDial::US.check('404-154-7372') => false # Can't start exchange code with 1
|
9
|
+
WillItDial::US.check('404-054-7372') => false # Can't start exchange code with 0
|
10
|
+
WillItDial::US.check('404-404-0404') => false # Suspicious, only 2 unique digits
|
11
|
+
WillItDial::US.check('404-555-1212') => false # Explicitly banned
|
12
|
+
WillItDial::US.check('247-464-2039') => false # Fake area code
|
13
|
+
|
14
|
+
Defaults to US
|
15
|
+
|
16
|
+
WillItDial('404-332-1494') => true
|
17
|
+
|
18
|
+
|
19
|
+
## Todo
|
20
|
+
|
21
|
+
* Better configuration options, increase or decrease paranoia
|
22
|
+
* Build an international version
|
23
|
+
|
24
|
+
## Copyright
|
25
|
+
|
26
|
+
Copyright (c) 2010 Mark Percival. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "will_it_dial"
|
8
|
+
gem.summary = %Q{A paranoid validator for phone numbers}
|
9
|
+
gem.description = %Q{Used to validate phone numbers that customers enter.
|
10
|
+
It will detect numbers that while technically valid, seem suspicious}
|
11
|
+
gem.email = "mark@mpercival.com"
|
12
|
+
gem.homepage = "http://github.com/markpercival/will_it_dial"
|
13
|
+
gem.authors = ["Mark Percival"]
|
14
|
+
gem.add_development_dependency "rspec", ">= 0"
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "will_it_dial #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/lib/will_it_dial.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
module WillItDial
|
2
|
+
class US
|
3
|
+
|
4
|
+
attr_reader :number
|
5
|
+
|
6
|
+
def self.check(num)
|
7
|
+
inst = self.new(num)
|
8
|
+
inst.check
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(phonenumber)
|
12
|
+
self.number = phonenumber
|
13
|
+
end
|
14
|
+
|
15
|
+
def check
|
16
|
+
!(invalid? || suspicious? || banned?)
|
17
|
+
end
|
18
|
+
|
19
|
+
def invalid?
|
20
|
+
too_short? || fake_area_code? || fake_exchange_code?
|
21
|
+
end
|
22
|
+
|
23
|
+
def suspicious?
|
24
|
+
(!!number.match(/1234/) || same_numbers?(number[-4,4]) || (unique_numbers(number) <= 2) || duplicates?)
|
25
|
+
end
|
26
|
+
|
27
|
+
def banned?
|
28
|
+
banned_numbers.include?(number[3,8])
|
29
|
+
end
|
30
|
+
|
31
|
+
def valid?
|
32
|
+
!invalid?
|
33
|
+
end
|
34
|
+
|
35
|
+
def number=(phonenumber)
|
36
|
+
@number = phonenumber.gsub(/[^0-9]/, '')
|
37
|
+
if @number[0,1].to_i == 1
|
38
|
+
@number = @number[1, @number.length - 1]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def too_short?(len = 10)
|
43
|
+
number.length < len
|
44
|
+
end
|
45
|
+
|
46
|
+
def duplicates?(max_dupes = 7)
|
47
|
+
num_arr = number.split('')
|
48
|
+
num_arr[0,num_arr.length - max_dupes + 1].each_with_index do |n,i|
|
49
|
+
if same_numbers?(num_arr[i,max_dupes])
|
50
|
+
return true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
56
|
+
def fake_exchange_code?
|
57
|
+
(number[3,1].to_i == 1) || (number[3,1].to_i == 0)
|
58
|
+
end
|
59
|
+
|
60
|
+
def fake_area_code?
|
61
|
+
!all_area_codes.include?(number[0,3])
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
# pass in an array of numbers and see if they are the same
|
67
|
+
def same_numbers?(num_arr)
|
68
|
+
if num_arr.is_a? String
|
69
|
+
num_arr = num_arr.split('')
|
70
|
+
end
|
71
|
+
na = num_arr.dup
|
72
|
+
na.delete(na.first)
|
73
|
+
na.empty?
|
74
|
+
end
|
75
|
+
|
76
|
+
def unique_numbers(num_arr)
|
77
|
+
if num_arr.is_a? String
|
78
|
+
num_arr = num_arr.split('')
|
79
|
+
end
|
80
|
+
num_arr.uniq.size
|
81
|
+
end
|
82
|
+
|
83
|
+
def all_area_codes
|
84
|
+
["201", "202", "203", "204", "205", "206", "207", "208", "209", "210", "212", "213", "214", "215", "216", "217", "218", "219", "224", "225", "226", "227", "228", "229", "231", "234", "236", "239", "240", "242", "246", "248", "249", "250", "251", "252", "253", "254", "256", "260", "262", "264", "267", "268", "269", "270", "274", "276", "281", "283", "284", "289", "301", "302", "303", "304", "305", "306", "307", "308", "309", "310", "312", "313", "314", "315", "316", "317", "318", "319", "320", "321", "323", "325", "327", "330", "331", "334", "336", "337", "339", "340", "341", "343", "345", "347", "351", "352", "360", "361", "364", "369", "380", "385", "386", "401", "402", "403", "404", "405", "406", "407", "408", "409", "410", "412", "413", "414", "415", "416", "417", "418", "419", "423", "424", "425", "430", "432", "434", "435", "438", "440", "441", "442", "443", "445", "447", "450", "458", "464", "469", "470", "473", "475", "478", "479", "480", "484", "501", "502", "503", "504", "505", "506", "507", "508", "509", "510", "512", "513", "514", "515", "516", "517", "518", "519", "520", "530", "531", "534", "539", "540", "541", "551", "557", "559", "561", "562", "563", "564", "567", "570", "571", "573", "574", "575", "579", "580", "581", "585", "586", "587", "601", "602", "603", "604", "605", "606", "607", "608", "609", "610", "612", "613", "614", "615", "616", "617", "618", "619", "620", "623", "626", "627", "628", "630", "631", "636", "641", "646", "647", "649", "650", "651", "657", "659", "660", "661", "662", "664", "667", "669", "670", "671", "678", "679", "681", "682", "684", "689", "701", "702", "703", "704", "705", "706", "707", "708", "709", "712", "713", "714", "715", "716", "717", "718", "719", "720", "721", "724", "727", "730", "731", "732", "734", "737", "740", "747", "754", "757", "758", "760", "762", "763", "764", "765", "767", "769", "770", "772", "773", "774", "775", "778", "779", "780", "781", "784", "785", "786", "787", "801", "802", "803", "804", "805", "806", "807", "808", "809", "810", "812", "813", "814", "815", "816", "817", "818", "819", "825", "828", "829", "830", "831", "832", "835", "843", "845", "847", "848", "849", "850", "856", "857", "858", "859", "860", "862", "863", "864", "865", "867", "868", "869", "870", "872", "876", "878", "901", "902", "903", "904", "905", "906", "907", "908", "909", "910", "912", "913", "914", "915", "916", "917", "918", "919", "920", "925", "928", "931", "935", "936", "937", "938", "939", "940", "941", "947", "949", "951", "952", "954", "956", "959", "970", "971", "972", "973", "975", "978", "979", "980", "984", "985", "989"]
|
85
|
+
end
|
86
|
+
|
87
|
+
def banned_numbers
|
88
|
+
['5551212']
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def WillItDial(num)
|
96
|
+
WillItDial::US.check(num)
|
97
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec'
|
2
|
+
require "lib/will_it_dial"
|
3
|
+
|
4
|
+
describe "A paranoid phone validator" do
|
5
|
+
|
6
|
+
|
7
|
+
it "should return true for valid numbers" do
|
8
|
+
WillItDial::US.check('404-514-6858').should be_true
|
9
|
+
WillItDial::US.check('1-404-514-6858').should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return false for suspicious numbers" do
|
13
|
+
WillItDial::US.check('404-404-0404').should be_false # Suspicious, only 2 unique digits
|
14
|
+
WillItDial::US.check('404-555-5555').should be_false # Suspcious
|
15
|
+
WillItDial::US.check('404-444-4449').should be_false # Suspcious, 7 same digits in a row
|
16
|
+
WillItDial::US.check('404-444-4489').should be_true # Suspcious but somewhat believable
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return false for invalid numbers" do
|
20
|
+
WillItDial::US.check('404-154-7372').should be_false # Can't start exchange code with 1
|
21
|
+
WillItDial::US.check('404-054-7372').should be_false # Can't start exchange code with 0
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return false for banned numbers" do
|
25
|
+
WillItDial::US.check('404-555-1212').should be_false # Explicitly banned
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should default to US when called generically" do
|
29
|
+
WillItDial('404-555-1212').should be_false
|
30
|
+
WillItDial('404-514-6858').should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: will_it_dial
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Percival
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-22 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: |-
|
26
|
+
Used to validate phone numbers that customers enter.
|
27
|
+
It will detect numbers that while technically valid, seem suspicious
|
28
|
+
email: mark@mpercival.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files:
|
34
|
+
- LICENSE
|
35
|
+
- README.markdown
|
36
|
+
files:
|
37
|
+
- .document
|
38
|
+
- .gitignore
|
39
|
+
- LICENSE
|
40
|
+
- Rakefile
|
41
|
+
- lib/will_it_dial.rb
|
42
|
+
- README.markdown
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/markpercival/will_it_dial
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --charset=UTF-8
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: A paranoid validator for phone numbers
|
71
|
+
test_files:
|
72
|
+
- spec/will_it_dial_us_spec.rb
|