module FFaker::IdentificationPL

Public Instance Methods

drivers_license() click to toggle source

Polish driver’s licence number en.wikipedia.org/wiki/Driving_licence_in_Poland

# File lib/ffaker/identification_pl.rb, line 33
def drivers_license
  FFaker.numerify('#####/##/####')
end
id()
Alias for: identity_card
identity_card() click to toggle source

Polish identity card number en.wikipedia.org/wiki/Polish_identity_card

# File lib/ffaker/identification_pl.rb, line 22
def identity_card
  letter_part = FFaker.letterify('???').upcase
  number_part = FFaker.numerify('#####')
  checksum = identity_card_checksum(letter_part, number_part)
  "#{letter_part}#{checksum}#{number_part}"
end
Also aliased as: id
pesel() click to toggle source

Polish national identification number en.wikipedia.org/wiki/PESEL

# File lib/ffaker/identification_pl.rb, line 12
def pesel
  date = generate_valid_pesel_date
  birthdate = pesel_birthdate(date)
  serial_number = FFaker.numerify('####')
  checksum = pesel_checksum(birthdate, serial_number)
  "#{birthdate}#{serial_number}#{checksum}"
end

Private Instance Methods

generate_valid_pesel_date() click to toggle source
# File lib/ffaker/identification_pl.rb, line 39
def generate_valid_pesel_date
  from = ::Date.new(1800, 1, 1)
  to = [::Date.today, ::Date.new(2299, 12, 31)].min
  fetch_sample(from..to)
end
identity_card_checksum(letter_part, number_part) click to toggle source
# File lib/ffaker/identification_pl.rb, line 71
def identity_card_checksum(letter_part, number_part)
  a, b, c = letter_part.codepoints.map { |codepoints| codepoints - 55 }
  d, e, f, g, h = number_part.chars.map(&:to_i)
  ((a * 7) + (b * 3) + c + (7 * d) + (3 * e) + f + (7 * g) + (3 * h)) % 10
end
pesel_birthdate(date) click to toggle source
# File lib/ffaker/identification_pl.rb, line 45
def pesel_birthdate(date)
  century_differentiator = pesel_century_differentiator(date.year)

  year = date.strftime('%y')
  month = century_differentiator.zero? ? date.strftime('%m') : date.month + century_differentiator
  day = date.strftime('%d')

  "#{year}#{month}#{day}"
end
pesel_century_differentiator(year) click to toggle source
# File lib/ffaker/identification_pl.rb, line 55
def pesel_century_differentiator(year)
  case year
  when 1800..1899 then 80
  when 2000..2099 then 20
  when 2100..2199 then 40
  when 2200..2299 then 60
  else 0
  end
end
pesel_checksum(date, serial_number) click to toggle source
# File lib/ffaker/identification_pl.rb, line 65
def pesel_checksum(date, serial_number)
  pesel_digits = "#{date}#{serial_number}".chars.map(&:to_i)
  a, b, c, d, e, f, g, h, i, j = pesel_digits
  ((a * 9) + (b * 7) + (c * 3) + d + (e * 9) + (f * 7) + (g * 3) + h + (i * 9) + (j * 7)) % 10
end