Created
April 17, 2017 17:04
-
-
Save juliends/715b7b124033ae7e888ae9bac24ddd92 to your computer and use it in GitHub Desktop.
Livecode_social_security_number
This file contains hidden or 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
require "date" | |
REGEXP = /^(?<gender>[12])(?<year>\d{2})(?<month>\d{2})(?<zip>\d{2})(\d{6})(?<key>\d{2})/ | |
DEPARTMENTS = { | |
"75" => "Paris", | |
"76" => "Seine Maritime" | |
} | |
def ssn_info(ssn) | |
# TODO "a man, born in March, 1986 in Paris." | |
reformated = ssn.gsub(" ", "").match(REGEXP) | |
type = reformated[:gender] == "1" ? "man" : "woman" | |
# if reformated[:gender] == "1" | |
# type = "man" | |
# else | |
# type = "woman" | |
# end | |
place = DEPARTMENTS[reformated[:zip]] | |
date_month = Date::MONTHNAMES[reformated[:month].to_i] | |
key = reformated[:key].to_i | |
number = ssn.gsub(" ","")[0,13].to_i | |
theorical_key = 97 - (number % 97) | |
if theorical_key == key | |
return "A #{type}, born in #{date_month} 19#{reformated[:year]} in #{place}" | |
else | |
return "Invalid ssn number" | |
end | |
end | |
p ssn_info("186037510803191") | |
p ssn_info("1 84 12 76 451 089 46") | |
p ssn_info("286107511451175") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment