Class: Faker::Vehicle
Constant Summary collapse
- MILEAGE_MIN =
10_000
- MILEAGE_MAX =
90_000
- VIN_KEYSPACE =
%w[A B C D E F G H J K L M N P R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9].freeze
- VIN_TRANSLITERATION =
{ A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8, J: 1, K: 2, L: 3, M: 4, N: 5, P: 7, R: 9, S: 2, T: 3, U: 4, V: 5, W: 6, X: 7, Y: 8, Z: 9 }.freeze
- VIN_WEIGHT =
[8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2].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(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.
-
.manufacturer ⇒ String
(also: manufacture)
Produces a random vehicle manufacturer.
-
.mileage(min: MILEAGE_MIN, max: MILEAGE_MAX) ⇒ Integer
(also: kilometrage)
Produces a random mileage/kilometrage for a vehicle.
-
.model(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.
-
.version ⇒ String
Produces a car version.
-
.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, 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
.car_options ⇒ Array<String>
Produces a random list of car options.
207 208 209 |
# File 'lib/faker/default/vehicle.rb', line 207 def Array.new(rand(5...10)) { fetch('vehicle.car_options') } end |
.car_type ⇒ String
Produces a random car type.
178 179 180 |
# File 'lib/faker/default/vehicle.rb', line 178 def car_type fetch('vehicle.car_types') end |
.color ⇒ String
Produces a random vehicle color.
126 127 128 |
# File 'lib/faker/default/vehicle.rb', line 126 def color fetch('vehicle.colors') end |
.doors ⇒ Integer Also known as: door_count
Produces a random vehicle door count.
234 235 236 |
# File 'lib/faker/default/vehicle.rb', line 234 def doors sample(fetch_all('vehicle.doors')) end |
.drive_type ⇒ String
Produces a random vehicle drive type.
152 153 154 |
# File 'lib/faker/default/vehicle.rb', line 152 def drive_type fetch('vehicle.drive_types') end |
.engine ⇒ String Also known as: engine_size
Produces a random engine cylinder count.
192 193 194 |
# File 'lib/faker/default/vehicle.rb', line 192 def engine "#{sample(fetch_all('vehicle.doors'))} #{fetch('vehicle.cylinder_engine')}" end |
.fuel_type ⇒ String
Produces a random vehicle fuel type.
165 166 167 |
# File 'lib/faker/default/vehicle.rb', line 165 def fuel_type fetch('vehicle.fuel_types') end |
.license_plate(state_abbreviation: '') ⇒ String
Produces a random license plate number.
283 284 285 286 287 288 |
# File 'lib/faker/default/vehicle.rb', line 283 def license_plate(state_abbreviation: '') 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.
68 69 70 |
# File 'lib/faker/default/vehicle.rb', line 68 def make fetch('vehicle.makes') end |
.make_and_model ⇒ String
Produces a random vehicle make and model.
98 99 100 101 102 |
# File 'lib/faker/default/vehicle.rb', line 98 def make_and_model m = make "#{m} #{model(make_of_model: m)}" end |
.manufacturer ⇒ String Also known as: manufacture
Produces a random vehicle manufacturer.
54 55 56 |
# File 'lib/faker/default/vehicle.rb', line 54 def manufacturer fetch('vehicle.manufacturer') end |
.mileage(min: MILEAGE_MIN, max: MILEAGE_MAX) ⇒ Integer Also known as: kilometrage
Produces a random mileage/kilometrage for a vehicle.
266 267 268 |
# File 'lib/faker/default/vehicle.rb', line 266 def mileage(min: MILEAGE_MIN, max: MILEAGE_MAX) rand_in_range(min, max) end |
.model(make_of_model: '') ⇒ String
Produces a random vehicle model.
83 84 85 86 87 |
# File 'lib/faker/default/vehicle.rb', line 83 def model(make_of_model: '') 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.
299 300 301 302 303 |
# File 'lib/faker/default/vehicle.rb', line 299 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.
220 221 222 |
# File 'lib/faker/default/vehicle.rb', line 220 def standard_specs Array.new(rand(5...10)) { fetch('vehicle.standard_specs') } end |
.style ⇒ String
Produces a random vehicle style.
113 114 115 |
# File 'lib/faker/default/vehicle.rb', line 113 def style fetch('vehicle.styles') end |
.transmission ⇒ String
Produces a random vehicle transmission.
139 140 141 |
# File 'lib/faker/default/vehicle.rb', line 139 def transmission fetch('vehicle.transmissions') end |
.version ⇒ String
Produces a car version
314 315 316 |
# File 'lib/faker/default/vehicle.rb', line 314 def version fetch('vehicle.version') end |
.vin ⇒ String
Produces a random vehicle VIN number.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/faker/default/vehicle.rb', line 24 def vin generate(:string) do |g| g.letter(name: :wmi, ranges: ['100'..'199', '400'..'499', '500'..'599', '700'..'799', '7A0'..'7F9']) g.letter(name: :vds, length: 5, ranges: [VIN_KEYSPACE]) g.computed(name: :checksum, deps: %i[wmi vds model_year plant_code vis]) do |wmi, vds, model_year, plant_code, vis| checksum = "#{wmi}#{vds}0#{model_year}#{plant_code}#{vis}".chars.each_with_index.map do |char, i| value = (char =~ /\A\d\z/ ? char.to_i : VIN_TRANSLITERATION[char.to_sym]) value * VIN_WEIGHT[i] end.inject(:+) % 11 if checksum == 10 'X' else checksum end end g.letter(name: :model_year, length: 1, ranges: [VIN_KEYSPACE - %w[U Z 0]]) g.letter(name: :plant_code, length: 1, ranges: [VIN_KEYSPACE]) g.int(name: :vis, length: 6) end end |