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'.freeze
VIN_MAP =
'0123456789X'.freeze
VIN_WEIGHTS =
'8765432X098765432'.freeze

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, respond_to_missing?, sample, shuffle, translate, unique, with_locale

Class Method Details

.car_optionsObject



82
83
84
# File 'lib/faker/vehicle.rb', line 82

def car_options
  Array.new(rand(5...10)) { fetch('vehicle.car_options') }
end

.car_typeObject



73
74
75
# File 'lib/faker/vehicle.rb', line 73

def car_type
  fetch('vehicle.car_types')
end

.colorObject



53
54
55
# File 'lib/faker/vehicle.rb', line 53

def color
  fetch('vehicle.colors')
end

.door_countObject



69
70
71
# File 'lib/faker/vehicle.rb', line 69

def door_count
  "#{fetch('vehicle.door_count')} #{fetch('vehicle.door')}"
end

.drive_typeObject



61
62
63
# File 'lib/faker/vehicle.rb', line 61

def drive_type
  fetch('vehicle.drive_types')
end

.engineObject Also known as: engine_size



77
78
79
# File 'lib/faker/vehicle.rb', line 77

def engine
  "#{fetch('vehicle.engine_size')} #{fetch('vehicle.cylinder_engine')}"
end

.fuel_typeObject



65
66
67
# File 'lib/faker/vehicle.rb', line 65

def fuel_type
  fetch('vehicle.fuel_types')
end

.makeObject



35
36
37
# File 'lib/faker/vehicle.rb', line 35

def make
  fetch('vehicle.makes')
end

.make_and_modelObject



44
45
46
47
# File 'lib/faker/vehicle.rb', line 44

def make_and_model
  m = make
  "#{m} #{model(m)}"
end

.manufactureObject



23
24
25
# File 'lib/faker/vehicle.rb', line 23

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

.mileageObject



27
28
29
# File 'lib/faker/vehicle.rb', line 27

def mileage
  rand_in_range(10_000, 90_000)
end

.model(make_of_model = '') ⇒ Object



39
40
41
42
# 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_specsObject



86
87
88
# File 'lib/faker/vehicle.rb', line 86

def standard_specs
  Array.new(rand(5...10)) { fetch('vehicle.standard_specs') }
end

.styleObject



49
50
51
# File 'lib/faker/vehicle.rb', line 49

def style
  fetch('vehicle.styles')
end

.transmissionObject



57
58
59
# File 'lib/faker/vehicle.rb', line 57

def transmission
  fetch('vehicle.transmissions')
end

.vinObject

ISO 3779



11
12
13
14
15
16
17
18
19
20
21
# 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

.yearObject



31
32
33
# File 'lib/faker/vehicle.rb', line 31

def year
  rand_in_range(2005, ::Time.now.year)
end