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.
-
.manufacture ⇒ String
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, 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.
195 196 197 |
# File 'lib/faker/default/vehicle.rb', line 195 def Array.new(rand(5...10)) { fetch('vehicle.car_options') } end |
.car_type ⇒ String
Produces a random car type.
166 167 168 |
# File 'lib/faker/default/vehicle.rb', line 166 def car_type fetch('vehicle.car_types') end |
.color ⇒ String
Produces a random vehicle color.
114 115 116 |
# File 'lib/faker/default/vehicle.rb', line 114 def color fetch('vehicle.colors') end |
.doors ⇒ Integer Also known as: door_count
Produces a random vehicle door count.
222 223 224 |
# File 'lib/faker/default/vehicle.rb', line 222 def doors sample(fetch_all('vehicle.doors')) end |
.drive_type ⇒ String
Produces a random vehicle drive type.
140 141 142 |
# File 'lib/faker/default/vehicle.rb', line 140 def drive_type fetch('vehicle.drive_types') end |
.engine ⇒ String Also known as: engine_size
Produces a random engine cylinder count.
180 181 182 |
# File 'lib/faker/default/vehicle.rb', line 180 def engine "#{sample(fetch_all('vehicle.doors'))} #{fetch('vehicle.cylinder_engine')}" end |
.fuel_type ⇒ String
Produces a random vehicle fuel type.
153 154 155 |
# File 'lib/faker/default/vehicle.rb', line 153 def fuel_type fetch('vehicle.fuel_types') end |
.license_plate(state_abbreviation: '') ⇒ String
Produces a random license plate number.
271 272 273 274 275 276 |
# File 'lib/faker/default/vehicle.rb', line 271 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.
56 57 58 |
# File 'lib/faker/default/vehicle.rb', line 56 def make fetch('vehicle.makes') end |
.make_and_model ⇒ String
Produces a random vehicle make and model.
86 87 88 89 90 |
# File 'lib/faker/default/vehicle.rb', line 86 def make_and_model m = make "#{m} #{model(make_of_model: m)}" end |
.manufacture ⇒ String
Produces a random vehicle manufacturer.
43 44 45 |
# File 'lib/faker/default/vehicle.rb', line 43 def manufacture fetch('vehicle.manufacture') end |
.mileage(min: MILEAGE_MIN, max: MILEAGE_MAX) ⇒ Integer Also known as: kilometrage
Produces a random mileage/kilometrage for a vehicle.
254 255 256 |
# File 'lib/faker/default/vehicle.rb', line 254 def mileage(min: MILEAGE_MIN, max: MILEAGE_MAX) rand_in_range(min, max) end |
.model(make_of_model: '') ⇒ String
Produces a random vehicle model.
71 72 73 74 75 |
# File 'lib/faker/default/vehicle.rb', line 71 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.
287 288 289 290 291 |
# File 'lib/faker/default/vehicle.rb', line 287 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.
208 209 210 |
# File 'lib/faker/default/vehicle.rb', line 208 def standard_specs Array.new(rand(5...10)) { fetch('vehicle.standard_specs') } end |
.style ⇒ String
Produces a random vehicle style.
101 102 103 |
# File 'lib/faker/default/vehicle.rb', line 101 def style fetch('vehicle.styles') end |
.transmission ⇒ String
Produces a random vehicle transmission.
127 128 129 |
# File 'lib/faker/default/vehicle.rb', line 127 def transmission fetch('vehicle.transmissions') end |
.version ⇒ String
Produces a car version
302 303 304 |
# File 'lib/faker/default/vehicle.rb', line 302 def version fetch('vehicle.version') end |
.vin ⇒ String
Produces a random vehicle VIN number.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/faker/default/vehicle.rb', line 24 def vin front = 8.times.map { VIN_KEYSPACE.sample(random: Faker::Config.random) }.join back = 8.times.map { VIN_KEYSPACE.sample(random: Faker::Config.random) }.join checksum = "#{front}A#{back}".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 checksum = 'X' if checksum == 10 "#{front}#{checksum}#{back}" end |