Module: FFaker::IdentificationKr

Extended by:
IdentificationKr, ModuleUtils
Included in:
IdentificationKr
Defined in:
lib/ffaker/identification_kr.rb

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, underscore

Instance Method Details

#rrnObject


10
11
12
13
14
15
16
17
# File 'lib/ffaker/identification_kr.rb', line 10

def rrn
  birth = [*Date.new(1970, 1, 1)..Date.new(1999, 12, 31)].sample.strftime('%y%d%m')
  sex = [1, 2].sample
  loc = FFaker.numerify("#{[*'00'..'95'].sample}###")
  a, b, c, d, e, f, g, h, i, j, k, l = "#{birth}#{sex}#{loc}".split(//).map(&:to_i)
  checksum = (11 - (2 * a + 3 * b + 4 * c + 5 * d + 6 * e + 7 * f + 8 * g + 9 * h + 2 * i + 3 * j + 4 * k + 5 * l) % 11) % 10
  "#{birth}-#{sex}#{loc}#{checksum}"
end