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, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, shuffle!, translate, unique, with_locale

Class Method Details

.british_driving_licence(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.

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:



26
27
28
29
30
31
32
33
# File 'lib/faker/default/driving_licence.rb', line 26

def british_driving_licence(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))
  [
    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:



44
45
46
# File 'lib/faker/default/driving_licence.rb', line 44

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:



64
65
66
67
68
69
70
# File 'lib/faker/default/driving_licence.rb', line 64

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:



83
84
85
86
87
# File 'lib/faker/default/driving_licence.rb', line 83

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