-
-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# # Number: A possible phone number, E164 or not. | ||
# # Hints: Information that helps or constricts the plausibility check. | ||
# # | ||
# plausible? number, hints = {} | ||
# | ||
|
||
# plausible? number # Uses the definitions from the country definition to plausibility check. | ||
# plausible? number, cc: 1 # => Checks cc. | ||
# plausible? number, pattern: /[^5]/ # Uses def, checks against split. | ||
# plausible? number, country: 1, pattern: [3, 4, 3] # Uses given country – adds cc. | ||
# | ||
|
||
# Basic plausibility is: | ||
# * Max digits are 15. | ||
# * Min digits are 2 (?) | ||
# | ||
|
||
module Phony | ||
|
||
class Validator | ||
|
||
# TODO Beautify. | ||
# | ||
def plausible? number, hints = {} | ||
normalized = normalize number | ||
|
||
# False if it fails the basic check. | ||
# | ||
return false unless normalized.size === (2..15) | ||
|
||
# Hint based checking. | ||
# | ||
cc, ndc, *rest = split normalized | ||
|
||
# CC. | ||
# | ||
cc_needed = hints[:cc] | ||
return false if cc_needed && cc_needed != cc | ||
|
||
# NDC. | ||
# | ||
ndc_needed = hints[:ndc] | ||
return false if ndc_needed && ndc_needed != ndc | ||
|
||
# Country specific checks? | ||
# | ||
|
||
# Get the country. | ||
# | ||
|
||
# Check. | ||
# | ||
|
||
rescue StandardError | ||
return false | ||
end | ||
|
||
def normalize number | ||
number | ||
end | ||
|
||
end | ||
|
||
end |