Advertisement
VladikOtez

Driver

Apr 30th, 2017
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.06 KB | None | 0 0
  1. def driver(data)
  2.  
  3. [make_last_name(data[2]).upcase!,decade_digit(data[3]),if_fem(month(data[3]),data[-1]),day(data[3]),data[3].chars.last,initials(data[0],data[1]),"9AA"].join("")
  4. end
  5. def make_last_name str
  6.  return str if str.size==5
  7.  num= "9"*(5-str.size)
  8.   if str.size<5
  9.     "#{str}"+"#{num}"
  10.   end
  11. end
  12. def decade_digit str
  13.    ary= str[-4..-1]
  14.   ary[-2]
  15. end
  16. def month str
  17.   ary=str[3..5]
  18.   case ary
  19.     when  /Jan|Jan\w*/
  20.      "01"
  21.     when /Feb|Feb\w*/
  22.       "02"
  23.     when /Mar|Mar\w*/
  24.       "03"
  25.     when /Apr|Apr\w*/
  26.       "04"
  27.     when /May|May\w*/
  28.       "05"
  29.     when /Jun|Jun\w*/
  30.       "06"
  31.     when /Jul|Jul\w*/
  32.       "07"
  33.     when /Aug|Aug\w*/
  34.       "08"
  35.     when /Sep|Sep\w*/
  36.       "09"
  37.     when /Oct|Oct\w*/
  38.       "10"
  39.     when /Nov|Nov\w*/
  40.       "11"
  41.     when /Dec|Dec\w*/
  42.       "12"
  43.   end
  44.  
  45. end
  46. def if_fem num,str
  47.   if str=="F" || str== 'f'
  48.    kek= (num[0].to_i+5).to_s<<num[1]
  49.   end
  50.   kek
  51. end
  52. def day str
  53.   str[0..1]
  54. end
  55. def initials str1,str2
  56.   if !str2.empty?
  57.     str1[0]+str2[0]
  58.   else
  59.     str1[0]+"9"
  60.   end
  61.  
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement