Class: Faker::Vehicle

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/vehicle.rb

Constant Summary collapse

VIN_CHARS =
'0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ'
VIN_MAP =
'0123456789X'
VIN_WEIGHTS =
'8765432X098765432'

Constants inherited from Base

Base::Letters, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, sample, shuffle, translate, unique, with_locale

Class Method Details

.manufactureObject



21
22
23
# File 'lib/faker/vehicle.rb', line 21

def manufacture
  sample(fetch_all('vehicle.manufacture')).first
end

.vinObject

ISO 3779



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/faker/vehicle.rb', line 9

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