class Faker::DrivingLicence

Constants

GB_PADDING
NI_CHANCE

Public Class Methods

british_driving_licence(legacy_last_name = NOT_GIVEN, legacy_initials = NOT_GIVEN, legacy_gender = NOT_GIVEN, legacy_date_of_birth = NOT_GIVEN, last_name: Faker::Name.last_name, initials: Faker::Name.initials, gender: random_gender, date_of_birth: Faker::Date.birthday(min_age: 18, max_age: 65)) click to toggle source

rubocop:disable Metrics/ParameterLists

# File lib/faker/default/driving_licence.rb, line 10
def british_driving_licence(legacy_last_name = NOT_GIVEN, legacy_initials = NOT_GIVEN, legacy_gender = NOT_GIVEN, legacy_date_of_birth = NOT_GIVEN, last_name: Faker::Name.last_name, initials: Faker::Name.initials, gender: random_gender, date_of_birth: Faker::Date.birthday(min_age: 18, max_age: 65))
  # rubocop:enable Metrics/ParameterLists
  warn_for_deprecated_arguments do |keywords|
    keywords << :last_name if legacy_last_name != NOT_GIVEN
    keywords << :initials if legacy_initials != NOT_GIVEN
    keywords << :gender if legacy_gender != NOT_GIVEN
    keywords << :date_of_birth if legacy_date_of_birth != NOT_GIVEN
  end

  [
    gb_licence_padding(last_name, 5),
    gb_licence_year(date_of_birth, gender),
    gb_licence_padding(initials, 2),
    gb_licence_checksum
  ].join
end
northern_irish_driving_licence() click to toggle source
# File lib/faker/default/driving_licence.rb, line 27
def northern_irish_driving_licence
  Faker::Number.number(digits: 8).to_s
end
uk_driving_licence(*args) click to toggle source
# File lib/faker/default/driving_licence.rb, line 31
def uk_driving_licence(*args)
  if Faker::Config.random.rand < NI_CHANCE
    northern_irish_driving_licence
  else
    british_driving_licence(*args)
  end
end

Private Class Methods

gb_licence_checksum() click to toggle source
# File lib/faker/default/driving_licence.rb, line 60
def gb_licence_checksum
  regexify(/[0-9][A-Z][A-Z]/)
end
gb_licence_padding(str, num_chars) click to toggle source
# File lib/faker/default/driving_licence.rb, line 45
def gb_licence_padding(str, num_chars)
  prepped = str.upcase.gsub(%r{[^A-Z]}, '') + GB_PADDING
  prepped[0..(num_chars - 1)]
end
gb_licence_year(dob, gender) click to toggle source
# File lib/faker/default/driving_licence.rb, line 50
def gb_licence_year(dob, gender)
  decade = (dob.year / 10) % 10
  year = dob.year % 10
  month = gender == :female ? dob.month + 50 : dob.month
  # Rubocop's preferred formatting is pretty gory
  # rubocop:disable Style/FormatString
  "#{decade}#{'%02d' % month}#{'%02d' % dob.day}#{year}"
  # rubocop:enable Style/FormatString
end
random_gender() click to toggle source
# File lib/faker/default/driving_licence.rb, line 41
def random_gender
  %i[male female].sample(random: Faker::Config.random)
end