Class: Faker::DrivingLicence

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/driving_licence.rb

Constant Summary collapse

GB_PADDING =
'9999'
NI_CHANCE =

NI Pop is about 3% of total UK population

0.03

Constants inherited from Base

Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale

Class Method Details

.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)) ⇒ String

Produces a random British driving licence number.

rubocop:disable Metrics/ParameterLists

Examples:

Faker::DrivingLicence.british_driving_licence        #=> "MCDER712081VF7EK"
Faker::DrivingLicence.british_driving_licence(last_name: "O'Carroll",
                                              initials: "J",
                                              gender: :female,
                                              date_of_birth: Date.parse("1986-10-24")) #=> "OCARR815246J91HT"

Parameters:

  • last_name (String) (defaults to: Faker::Name.last_name)

    The last name of the driving licence's owner.

  • initials (String) (defaults to: Faker::Name.initials)

    The initials of the driving licence's owner.

  • gender (String) (defaults to: random_gender)

    The gender of the driving licence's owner.

  • date_of_birth (String) (defaults to: Faker::Date.birthday(min_age: 18, max_age: 65))

    The date of birth of the driving licence's owner.

Returns:

  • (String)

Available since:

  • 1.9.2


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/faker/default/driving_licence.rb', line 27

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_licenceString

Produces a random Northern Irish licence number.

Examples:

Faker::DrivingLicence.northern_irish_driving_licence #=> "70702548"

Returns:

  • (String)

Available since:

  • 1.9.2


53
54
55
# File 'lib/faker/default/driving_licence.rb', line 53

def northern_irish_driving_licence
  Faker::Number.number(digits: 8).to_s
end

.uk_driving_licence(last_name, initials, gender, date_of_birth) ⇒ String .uk_driving_licenceString

Produces a random UK driving licence number in either GB or NI format, at a rate consistent with their relative populations

Examples:

Faker::DrivingLicence.uk_driving_licence             #=> "OCARR815246J91HT"
Faker::DrivingLicence.uk_driving_licence             #=> "70702548"

Overloads:

  • .uk_driving_licence(last_name, initials, gender, date_of_birth) ⇒ String

    Parameters:

    • last_name (String)

      The last name of the driving licence's owner.

    • initials (String)

      The initials of the driving licence's owner.

    • gender (String)

      The gender of the driving licence's owner.

    • date_of_birth (String)

      The date of birth of the driving licence's owner.

Returns:

  • (String)

Available since:

  • 1.9.2


73
74
75
76
77
78
79
# File 'lib/faker/default/driving_licence.rb', line 73

def uk_driving_licence(*args)
  if Faker::Config.random.rand < NI_CHANCE
    northern_irish_driving_licence
  else
    british_driving_licence(*args)
  end
end

.usa_driving_licence(state = 'California') ⇒ String

Produces a random USA driving licence number by state code passed.

Examples:

Faker::DrivingLicence.usa_driving_licence                 #=> "V5598249"
Faker::DrivingLicence.usa_driving_licence('new mexico')   #=> "270692028"
Faker::DrivingLicence.usa_driving_licence('New Mexico')   #=> "68178637"

Returns:

  • (String)

Available since:

  • next


92
93
94
95
96
# File 'lib/faker/default/driving_licence.rb', line 92

def usa_driving_licence(state = 'California')
  bothify(fetch("driving_licence.usa.#{state.to_s.strip.downcase.gsub(' ', '_')}"))
rescue I18n::MissingTranslationData => _e
  raise InvalidStatePassed, "Invalid state code passed for USA, '#{state}'"
end