class Faker::Vehicle
Public Class Methods
manufacture()
click to toggle source
# File lib/faker/vehicle.rb, line 21 def manufacture fetch_all('vehicle.manufacture').sample["name"] end
vin()
click to toggle source
ISO 3779
# File lib/faker/vehicle.rb, line 9 def vin manufacture = fetch_all('vehicle.manufacture').sample c = @vin_chars.split('').reject{ |n| n == '.'} vehicle_identification_number = manufacture["wmi"].split('').concat( Array.new(14) { c.sample } ) (12..14).to_a.each_with_index { |n, i| vehicle_identification_number[n] = manufacture["win_ext"][i] } unless manufacture["win_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 27 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 31 def vin_checksum(vehicle_identification_number) @vin_map[vehicle_identification_number.each_with_index.map(&method(:calculate_vin_weight)).inject(:+) % 11] end