Skip to content

Commit

Permalink
+ validator experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Mar 15, 2012
1 parent e296863 commit c957a70
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions lib/phony/validator.rb
@@ -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

0 comments on commit c957a70

Please sign in to comment.