class Faker::Vehicle
Constants
- VIN_CHARS
- VIN_MAP
- VIN_WEIGHTS
Public Class Methods
car_options()
click to toggle source
# File lib/faker/vehicle.rb, line 82 def car_options Array.new(rand(5...10)) { fetch('vehicle.car_options') } end
car_type()
click to toggle source
# File lib/faker/vehicle.rb, line 73 def car_type fetch('vehicle.car_types') end
color()
click to toggle source
# File lib/faker/vehicle.rb, line 53 def color fetch('vehicle.colors') end
door_count()
click to toggle source
# File lib/faker/vehicle.rb, line 69 def door_count "#{fetch('vehicle.door_count')} #{fetch('vehicle.door')}" end
drive_type()
click to toggle source
# File lib/faker/vehicle.rb, line 61 def drive_type fetch('vehicle.drive_types') end
engine()
click to toggle source
# File lib/faker/vehicle.rb, line 77 def engine "#{fetch('vehicle.engine_size')} #{fetch('vehicle.cylinder_engine')}" end
Also aliased as: engine_size
fuel_type()
click to toggle source
# File lib/faker/vehicle.rb, line 65 def fuel_type fetch('vehicle.fuel_types') end
make()
click to toggle source
# File lib/faker/vehicle.rb, line 35 def make fetch('vehicle.makes') end
make_and_model()
click to toggle source
# File lib/faker/vehicle.rb, line 44 def make_and_model m = make "#{m} #{model(m)}" end
manufacture()
click to toggle source
# File lib/faker/vehicle.rb, line 23 def manufacture sample(fetch_all('vehicle.manufacture')).first end
mileage()
click to toggle source
# File lib/faker/vehicle.rb, line 27 def mileage rand_in_range(10_000, 90_000) end
model(make_of_model = '')
click to toggle source
# File lib/faker/vehicle.rb, line 39 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
standard_specs()
click to toggle source
# File lib/faker/vehicle.rb, line 86 def standard_specs Array.new(rand(5...10)) { fetch('vehicle.standard_specs') } end
style()
click to toggle source
# File lib/faker/vehicle.rb, line 49 def style fetch('vehicle.styles') end
transmission()
click to toggle source
# File lib/faker/vehicle.rb, line 57 def transmission fetch('vehicle.transmissions') end
vin()
click to toggle source
ISO 3779
# File lib/faker/vehicle.rb, line 11 def vin _, wmi, wmi_ext = sample(fetch_all('vehicle.manufacture')) c = VIN_CHARS.split('').reject { |n| n == '.' } vehicle_identification_number = wmi.split('').concat(Array.new(14) { sample(c) }) (12..14).to_a.each_with_index { |n, i| vehicle_identification_number[n] = wmi_ext[i] } unless wmi_ext.nil? vehicle_identification_number[10] = fetch('vehicle.year') vehicle_identification_number[8] = vin_checksum(vehicle_identification_number) vehicle_identification_number.join.upcase end
year()
click to toggle source
# File lib/faker/vehicle.rb, line 31 def year rand_in_range(2005, ::Time.now.year) end
Private Class Methods
calculate_vin_weight(character, idx)
click to toggle source
# File lib/faker/vehicle.rb, line 92 def calculate_vin_weight(character, idx) (VIN_CHARS.index(character) % 10) * VIN_MAP.index(VIN_WEIGHTS[idx]) end
vin_checksum(vehicle_identification_number)
click to toggle source
# File lib/faker/vehicle.rb, line 96 def vin_checksum(vehicle_identification_number) VIN_MAP[vehicle_identification_number.each_with_index.map(&method(:calculate_vin_weight)).inject(:+) % 11] end