class Faker::Vehicle
Constants
- VIN_CHARS
- VIN_MAP
- VIN_WEIGHTS
Public Class Methods
manufacture()
click to toggle source
# File lib/faker/vehicle.rb, line 23 def manufacture sample(fetch_all('vehicle.manufacture')).first 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
Private Class Methods
calculate_vin_weight(character, i)
click to toggle source
# File lib/faker/vehicle.rb, line 29 def calculate_vin_weight(character, i) (VIN_CHARS.index(character) % 10) * VIN_MAP.index(VIN_WEIGHTS[i]) end
vin_checksum(vehicle_identification_number)
click to toggle source
# File lib/faker/vehicle.rb, line 33 def vin_checksum(vehicle_identification_number) VIN_MAP[vehicle_identification_number.each_with_index.map(&method(:calculate_vin_weight)).inject(:+) % 11] end