Skip to content

Instantly share code, notes, and snippets.

@RobertoBarros
Created July 11, 2016 21:22
Show Gist options
  • Save RobertoBarros/e00df9e73d88d87b75b84032b28a6f73 to your computer and use it in GitHub Desktop.
Save RobertoBarros/e00df9e73d88d87b75b84032b28a6f73 to your computer and use it in GitHub Desktop.
regex livecode
require "date"
def sex(cod)
if cod.to_i == 1
return "it's a man"
else
return "it's a woman"
end
end
def birth(month, year)
month_str = Date::MONTHNAMES[month.to_i]
return " Born in #{month_str}, #{year}"
end
def dep(cod_num)
departaments = {
'37' => 'Lot',
'76' => 'London',
'75' => 'Paris',
}
" in #{departaments[cod_num]} "
end
def french_ssn_info(ssn)
ssn_match = ssn.match(/^(?<sex>[1-2])\s?(?<year>[0-9]{2})\s?(?<month>[0-1][0-9])\s?(?<city>[0-9]{2})\s?(?<random>[0-9]{3}\s?[0-9]{3})\s?(?<key>[0-9]{2})/)
# (97 - ssn_without_key) by 97.
ssn_code = ssn_match[:sex] + ssn_match[:year] + ssn_match[:month] + ssn_match[:city] + ssn_match[:random].tr(" ","")
verification = (97 - ssn_code.to_i) % 97
return "Dumb SSN" if verification != ssn_match[:key].to_i
message = ""
message << sex(ssn_match[:sex])
message << birth(ssn_match[:month],ssn_match[:year])
message << dep(ssn_match[:city])
return message
end
ssn_list = [
"1 84 12 76 451 089 46",
"194073765893575",
"2 86 10 75 114 511 75"]
ssn_list.each do |ssn|
puts "#{ssn}: #{french_ssn_info(ssn)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment