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
- VIN_REGEX =
/\A[A-HJ-NPR-Z0-9]{17}\z/.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.
196 197 198 |
# File 'lib/faker/default/vehicle.rb', line 196 def Array.new(rand(5...10)) { fetch('vehicle.car_options') } end |
.car_type ⇒ String
Produces a random car type.
167 168 169 |
# File 'lib/faker/default/vehicle.rb', line 167 def car_type fetch('vehicle.car_types') end |
.color ⇒ String
Produces a random vehicle color.
115 116 117 |
# File 'lib/faker/default/vehicle.rb', line 115 def color fetch('vehicle.colors') end |
.doors ⇒ Integer Also known as: door_count
Produces a random vehicle door count.
223 224 225 |
# File 'lib/faker/default/vehicle.rb', line 223 def doors sample(fetch_all('vehicle.doors')) end |
.drive_type ⇒ String
Produces a random vehicle drive type.
141 142 143 |
# File 'lib/faker/default/vehicle.rb', line 141 def drive_type fetch('vehicle.drive_types') end |
.engine ⇒ String Also known as: engine_size
Produces a random engine cylinder count.
181 182 183 |
# File 'lib/faker/default/vehicle.rb', line 181 def engine "#{sample(fetch_all('vehicle.doors'))} #{fetch('vehicle.cylinder_engine')}" end |
.fuel_type ⇒ String
Produces a random vehicle fuel type.
154 155 156 |
# File 'lib/faker/default/vehicle.rb', line 154 def fuel_type fetch('vehicle.fuel_types') end |
.license_plate(state_abbreviation: '') ⇒ String
Produces a random license plate number.
272 273 274 275 276 277 |
# File 'lib/faker/default/vehicle.rb', line 272 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.
57 58 59 |
# File 'lib/faker/default/vehicle.rb', line 57 def make fetch('vehicle.makes') end |
.make_and_model ⇒ String
Produces a random vehicle make and model.
87 88 89 90 91 |
# File 'lib/faker/default/vehicle.rb', line 87 def make_and_model m = make "#{m} #{model(make_of_model: m)}" end |
.manufacture ⇒ String
Produces a random vehicle manufacturer.
44 45 46 |
# File 'lib/faker/default/vehicle.rb', line 44 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.
255 256 257 |
# File 'lib/faker/default/vehicle.rb', line 255 def mileage(min: MILEAGE_MIN, max: MILEAGE_MAX) rand_in_range(min, max) end |
.model(make_of_model: '') ⇒ String
Produces a random vehicle model.
72 73 74 75 76 |
# File 'lib/faker/default/vehicle.rb', line 72 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.
288 289 290 291 292 |
# File 'lib/faker/default/vehicle.rb', line 288 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.
209 210 211 |
# File 'lib/faker/default/vehicle.rb', line 209 def standard_specs Array.new(rand(5...10)) { fetch('vehicle.standard_specs') } end |
.style ⇒ String
Produces a random vehicle style.
102 103 104 |
# File 'lib/faker/default/vehicle.rb', line 102 def style fetch('vehicle.styles') end |
.transmission ⇒ String
Produces a random vehicle transmission.
128 129 130 |
# File 'lib/faker/default/vehicle.rb', line 128 def transmission fetch('vehicle.transmissions') end |
.version ⇒ String
Produces a car version
303 304 305 |
# File 'lib/faker/default/vehicle.rb', line 303 def version fetch('vehicle.version') end |
.vin ⇒ String
Produces a random vehicle VIN number.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/faker/default/vehicle.rb', line 25 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 |