File: identification_kr.rb

package info (click to toggle)
ruby-ffaker 2.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,776 kB
  • sloc: ruby: 12,788; makefile: 8; sh: 1
file content (26 lines) | stat: -rw-r--r-- 819 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

module FFaker
  module IdentificationKR
    extend ModuleUtils
    extend self

    # Resident Registration Number
    # http://ko.wikipedia.org/wiki/%EC%A3%BC%EB%AF%BC%EB%93%B1%EB%A1%9D%EB%B2%88%ED%98%B8
    def rrn
      birth = fetch_sample(::Date.new(1970, 1, 1)..::Date.new(1999, 12, 31)).strftime('%y%d%m')
      sex = fetch_sample([1, 2])
      loc = FFaker.numerify("#{fetch_sample(Array('00'..'95'))}###")
      a, b, c, d, e, f, g, h, i, j, k, l = "#{birth}#{sex}#{loc}".chars.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
  end
end