I am newbie in ruby and regular expressions and I have this function write in PHP, and I would need to rewrite it to Ruby.
function date_number_id($id_number) {
if (preg_match('~^([0-9]{2})([0-9]{2})([0-9]{2})/([0-9]{3,4})$~', $id_number, $match)) {
return (strlen($match[4]) < 4 || $match[1] >= 54 ? "19" : "20") . "$match[1]-" . sprintf("%02d", $match[2] % 50) . "-$match[3]";
}
else
{
return false;
}
}
Could you help me please, with it?
Many thanks!
EDIT: This is a function that prints from the identification number the birthday day. The input is for example: 890807/5089
Unless I missed something…
I think the mapping to PHP is obvious, but if there’s something you don’t understand why it is so, ask.