Class: Faker::Vehicle
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
-
.car_options ⇒ Array<String>
Produces a random list of car options.
-
.car_type ⇒ String
Produces a random car type.
-
.color ⇒ String
Produces a random vehicle color.
-
.doors ⇒ Integer
(also: door_count)
Produces a random vehicle door count.
-
.drive_type ⇒ String
Produces a random vehicle drive type.
-
.engine ⇒ String
(also: engine_size)
Produces a random engine cylinder count.
-
.fuel_type ⇒ String
Produces a random vehicle fuel type.
-
.license_plate(legacy_state_abreviation = NOT_GIVEN, state_abbreviation: '') ⇒ String
Produces a random license plate number.
-
.make ⇒ String
Produces a random vehicle make.
-
.make_and_model ⇒ String
Produces a random vehicle make and model.
-
.manufacture ⇒ String
Produces a random vehicle manufacturer.
-
.mileage(legacy_min = NOT_GIVEN, legacy_max = NOT_GIVEN, min: MILEAGE_MIN, max: MILEAGE_MAX) ⇒ Integer
(also: kilometrage)
Produces a random mileage/kilometrage for a vehicle.
-
.model(legacy_make_of_model = NOT_GIVEN, make_of_model: '') ⇒ String
Produces a random vehicle model.
-
.singapore_license_plate ⇒ String
Produces a random license plate number for Singapore.
-
.standard_specs ⇒ Array<String>
Produces a random list of standard specs.
-
.style ⇒ String
Produces a random vehicle style.
-
.transmission ⇒ String
Produces a random vehicle transmission.
-
.vin ⇒ String
Produces a random vehicle VIN number.
-
.year ⇒ Integer
Produces a random car year between 1 and 15 years ago.
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_options ⇒ Array<String>
Produces a random list of car options.
193 194 195 |
# File 'lib/faker/default/vehicle.rb', line 193 def Array.new(rand(5...10)) { fetch('vehicle.car_options') } end |
.car_type ⇒ String
Produces a random car type.
164 165 166 |
# File 'lib/faker/default/vehicle.rb', line 164 def car_type fetch('vehicle.car_types') end |
.color ⇒ String
Produces a random vehicle color.
112 113 114 |
# File 'lib/faker/default/vehicle.rb', line 112 def color fetch('vehicle.colors') end |
.doors ⇒ Integer Also known as: door_count
Produces a random vehicle door count.
220 221 222 |
# File 'lib/faker/default/vehicle.rb', line 220 def doors sample(fetch_all('vehicle.doors')) end |
.drive_type ⇒ String
Produces a random vehicle drive type.
138 139 140 |
# File 'lib/faker/default/vehicle.rb', line 138 def drive_type fetch('vehicle.drive_types') end |
.engine ⇒ String Also known as: engine_size
Produces a random engine cylinder count.
178 179 180 |
# File 'lib/faker/default/vehicle.rb', line 178 def engine "#{sample(fetch_all('vehicle.doors'))} #{fetch('vehicle.cylinder_engine')}" end |
.fuel_type ⇒ String
Produces a random vehicle fuel type.
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.
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 |
.make ⇒ String
Produces a random vehicle make.
50 51 52 |
# File 'lib/faker/default/vehicle.rb', line 50 def make fetch('vehicle.makes') end |
.make_and_model ⇒ String
Produces a random vehicle make and model.
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 |
.manufacture ⇒ String
Produces a random vehicle manufacturer.
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.
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.
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_plate ⇒ String
Produces a random license plate number for Singapore.
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_specs ⇒ Array<String>
Produces a random list of standard specs.
206 207 208 |
# File 'lib/faker/default/vehicle.rb', line 206 def standard_specs Array.new(rand(5...10)) { fetch('vehicle.standard_specs') } end |
.style ⇒ String
Produces a random vehicle style.
99 100 101 |
# File 'lib/faker/default/vehicle.rb', line 99 def style fetch('vehicle.styles') end |
.transmission ⇒ String
Produces a random vehicle transmission.
125 126 127 |
# File 'lib/faker/default/vehicle.rb', line 125 def transmission fetch('vehicle.transmissions') end |
.vin ⇒ String
Produces a random vehicle VIN number.
25 26 27 |
# File 'lib/faker/default/vehicle.rb', line 25 def vin regexify(VIN_REGEX) end |