module FFaker::IdentificationTW

Constants

AREA_CODE

Public Instance Methods

id() click to toggle source

Identity Card Number en.wikipedia.org/wiki/National_identification_card_(Taiwan)#Identity_card_number

# File lib/ffaker/identification_tw.rb, line 13
def id
  letter = FFaker.letterify('?')
  code = AREA_CODE[letter.to_sym]
  gender = fetch_sample([1, 2])
  serial = FFaker.numerify('#######')
  a, b, c, d, e, f, g, h, i, j = "#{code}#{gender}#{serial}".chars.map(&:to_i)

  checksum = ((9 * a) + b + (2 * c) + (3 * d) + (4 * e) + (5 * f) + (6 * g) + (7 * h) + (8 * i) + (9 * j)) % 10
  "#{letter.upcase}#{gender}#{serial}#{checksum}"
end