Class: Faker::Vehicle

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

Constant Summary collapse

MILEAGE_MIN =
10_000
MILEAGE_MAX =
90_000
VIN_LETTERS =
'ABCDEFGHJKLMNPRSTUVWXYZ'
VIN_MAP =
'0123456789X'
VIN_WEIGHTS =
'8765432X098765432'
VIN_REGEX =
/^[A-Z0-9]{3}[A-Z0-9]{5}[A-Z0-9]{1}[A-Z0-9]{1}[A-Z0-0]{1}[A-Z0-9]{1}\d{5}$/.freeze
SG_CHECKSUM_WEIGHTS =
[3, 14, 2, 12, 2, 11, 1].freeze
SG_CHECKSUM_CHARS =
'AYUSPLJGDBZXTRMKHEC'

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

.car_optionsArray<String>

Produces a random list of car options.

Examples:

Faker::Vehicle.car_options #=> ["DVD System", "MP3 (Single Disc)", "Tow Package", "CD (Multi Disc)", "Cassette Player", "Bucket Seats", "Cassette Player", "Leather Interior", "AM/FM Stereo", "Third Row Seats"]

Returns:

  • (Array<String>)

Available since:

  • 1.6.4


193
194
195
# File 'lib/faker/default/vehicle.rb', line 193

def car_options
  Array.new(rand(5...10)) { fetch('vehicle.car_options') }
end

.car_typeString

Produces a random car type.

Examples:

Faker::Vehicle.car_type #=> "Sedan"

Returns:

  • (String)

Available since:

  • 1.6.4


164
165
166
# File 'lib/faker/default/vehicle.rb', line 164

def car_type
  fetch('vehicle.car_types')
end

.colorString

Produces a random vehicle color.

Examples:

Faker::Vehicle.color #=> "Red"

Returns:

  • (String)

Available since:

  • 1.6.4


112
113
114
# File 'lib/faker/default/vehicle.rb', line 112

def color
  fetch('vehicle.colors')
end

.doorsInteger Also known as: door_count

Produces a random vehicle door count.

Examples:

Faker::Vehicle.doors #=> 1
Faker::Vehicle.door_count #=> 3

Returns:

  • (Integer)

Available since:

  • 1.6.4


220
221
222
# File 'lib/faker/default/vehicle.rb', line 220

def doors
  sample(fetch_all('vehicle.doors'))
end

.drive_typeString

Produces a random vehicle drive type.

Examples:

Faker::Vehicle.drive_type #=> "4x2/2-wheel drive"

Returns:

  • (String)

Available since:

  • 1.6.4


138
139
140
# File 'lib/faker/default/vehicle.rb', line 138

def drive_type
  fetch('vehicle.drive_types')
end

.engineString Also known as: engine_size

Produces a random engine cylinder count.

Examples:

Faker::Vehicle.engine_size #=> 6
Faker::Vehicle.engine #=> 4

Returns:

  • (String)

Available since:

  • 1.6.4


178
179
180
# File 'lib/faker/default/vehicle.rb', line 178

def engine
  "#{sample(fetch_all('vehicle.doors'))} #{fetch('vehicle.cylinder_engine')}"
end

.fuel_typeString

Produces a random vehicle fuel type.

Examples:

Faker::Vehicle.fuel_type #=> "Diesel"

Returns:

  • (String)

Available since:

  • 1.6.4


151
152
153
# File 'lib/faker/default/vehicle.rb', line 151

def fuel_type
  fetch('vehicle.fuel_types')
end

.license_plate(legacy_state_abreviation = NOT_GIVEN, state_abbreviation: '') ⇒ String

Produces a random license plate number.

Examples:

Faker::Vehicle.license_plate #=> "DEP-2483"
Faker::Vehicle.license_plate(state_abbreviation: 'FL') #=> "977 UNU"

Parameters:

  • state_abbreviation (String) (defaults to: '')

    Two letter state abbreviation for license plate generation.

Returns:

  • (String)

Available since:

  • 1.6.4


274
275
276
277
278
279
280
281
282
283
# File 'lib/faker/default/vehicle.rb', line 274

def license_plate(legacy_state_abreviation = NOT_GIVEN, state_abbreviation: '')
  warn_for_deprecated_arguments do |keywords|
    keywords << :state_abbreviation if legacy_state_abreviation != NOT_GIVEN
  end

  return regexify(bothify(fetch('vehicle.license_plate'))) if state_abbreviation.empty?

  key = 'vehicle.license_plate_by_state.' + state_abbreviation
  regexify(bothify(fetch(key)))
end

.makeString

Produces a random vehicle make.

Examples:

Faker::Vehicle.make #=> "Honda"

Returns:

  • (String)

Available since:

  • 1.6.4


50
51
52
# File 'lib/faker/default/vehicle.rb', line 50

def make
  fetch('vehicle.makes')
end

.make_and_modelString

Produces a random vehicle make and model.

Examples:

Faker::Vehicle.make_and_model #=> "Dodge Charger"

Returns:

  • (String)

Available since:

  • 1.6.4


84
85
86
87
88
# File 'lib/faker/default/vehicle.rb', line 84

def make_and_model
  m = make

  "#{m} #{model(make_of_model: m)}"
end

.manufactureString

Produces a random vehicle manufacturer.

Examples:

Faker::Vehicle.manufacture #=> "Lamborghini"

Returns:

  • (String)

Available since:

  • 1.6.4


37
38
39
# File 'lib/faker/default/vehicle.rb', line 37

def manufacture
  fetch('vehicle.manufacture')
end

.mileage(legacy_min = NOT_GIVEN, legacy_max = NOT_GIVEN, min: MILEAGE_MIN, max: MILEAGE_MAX) ⇒ Integer Also known as: kilometrage

Produces a random mileage/kilometrage for a vehicle.

Examples:

Faker::Vehicle.mileage #=> 26961
Faker::Vehicle.mileage(min: 50_000) #=> 81557
Faker::Vehicle.mileage(min: 50_000, max: 250_000) #=> 117503
Faker::Vehicle.kilometrage #=> 35378

Parameters:

  • min (Integer) (defaults to: MILEAGE_MIN)

    Specific minimum limit for mileage generation.

  • max (Integer) (defaults to: MILEAGE_MAX)

    Specific maximum limit for mileage generation.

Returns:

  • (Integer)

Available since:

  • 1.6.4


252
253
254
255
256
257
258
259
# File 'lib/faker/default/vehicle.rb', line 252

def mileage(legacy_min = NOT_GIVEN, legacy_max = NOT_GIVEN, min: MILEAGE_MIN, max: MILEAGE_MAX)
  warn_for_deprecated_arguments do |keywords|
    keywords << :min if legacy_min != NOT_GIVEN
    keywords << :max if legacy_max != NOT_GIVEN
  end

  rand_in_range(min, max)
end

.model(legacy_make_of_model = NOT_GIVEN, make_of_model: '') ⇒ String

Produces a random vehicle model.

Examples:

Faker::Vehicle.model #=> "A8"
Faker::Vehicle.model(make_of_model: 'Toyota') #=> "Prius"

Parameters:

  • make_of_model (String) (defaults to: '')

    Specific valid vehicle make.

Returns:

  • (String)

Available since:

  • 1.6.4


65
66
67
68
69
70
71
72
73
# File 'lib/faker/default/vehicle.rb', line 65

def model(legacy_make_of_model = NOT_GIVEN, make_of_model: '')
  warn_for_deprecated_arguments do |keywords|
    keywords << :make_of_model if legacy_make_of_model != NOT_GIVEN
  end

  return fetch("vehicle.models_by_make.#{make}") if make_of_model.empty?

  fetch("vehicle.models_by_make.#{make_of_model}")
end

.singapore_license_plateString

Produces a random license plate number for Singapore.

Examples:

Faker::Vehicle.singapore_license_plate #=> "SLV1854M"

Returns:

  • (String)

Available since:

  • 1.6.4


294
295
296
297
298
# File 'lib/faker/default/vehicle.rb', line 294

def singapore_license_plate
  key = 'vehicle.license_plate'
  plate_number = regexify(bothify(fetch(key)))
  "#{plate_number}#{singapore_checksum(plate_number)}"
end

.standard_specsArray<String>

Produces a random list of standard specs.

Examples:

Faker::Vehicle.standard_specs #=> ["Full-size spare tire w/aluminum alloy wheel", "Back-up camera", "Carpeted cargo area", "Silver accent IP trim finisher -inc: silver shifter finisher", "Back-up camera", "Water-repellent windshield & front door glass", "Floor carpeting"]

Returns:

  • (Array<String>)

Available since:

  • 1.6.4


206
207
208
# File 'lib/faker/default/vehicle.rb', line 206

def standard_specs
  Array.new(rand(5...10)) { fetch('vehicle.standard_specs') }
end

.styleString

Produces a random vehicle style.

Examples:

Faker::Vehicle.style #=> "ESi"

Returns:

  • (String)

Available since:

  • 1.6.4


99
100
101
# File 'lib/faker/default/vehicle.rb', line 99

def style
  fetch('vehicle.styles')
end

.transmissionString

Produces a random vehicle transmission.

Examples:

Faker::Vehicle.transmission #=> "Automanual"

Returns:

  • (String)

Available since:

  • 1.6.4


125
126
127
# File 'lib/faker/default/vehicle.rb', line 125

def transmission
  fetch('vehicle.transmissions')
end

.vinString

Produces a random vehicle VIN number.

Examples:

Faker::Vehicle.vin #=> "LLDWXZLG77VK2LUUF"

Returns:

  • (String)

Available since:

  • 1.6.4


25
26
27
# File 'lib/faker/default/vehicle.rb', line 25

def vin
  regexify(VIN_REGEX)
end

.yearInteger

Produces a random car year between 1 and 15 years ago.

Examples:

Faker::Vehicle.year #=> 2008

Returns:

  • (Integer)

Available since:

  • 1.6.4


234
235
236
# File 'lib/faker/default/vehicle.rb', line 234

def year
  Faker::Time.backward(days: rand_in_range(365, 5475), period: :all, format: '%Y').to_i
end