Class: Faker::Vehicle

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

Constant Summary collapse

MILEAGE_MIN =
10_000
MILEAGE_MAX =
90_000
VIN_LETTERS =
'ABCDEFGHJKLMNPRSTUVWXYZ'
VIN_MAP =
'0123456789X'
VIN_WEIGHTS =
'8765432X098765432'
VIN_REGEX =
/^[A-Z0-9]{3}[A-Z0-9]{5}[A-Z0-9]{1}[A-Z0-9]{1}[A-Z0-0]{1}[A-Z0-9]{1}\d{5}$/
SG_CHECKSUM_WEIGHTS =
[3, 14, 2, 12, 2, 11, 1].freeze
SG_CHECKSUM_CHARS =
'AYUSPLJGDBZXTRMKHEC'

Constants inherited from Base

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

Class Method Summary collapse

Methods inherited from Base

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

Class Method Details

.car_optionsObject


71
72
73
# File 'lib/faker/default/vehicle.rb', line 71

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

.car_typeObject


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

def car_type
  fetch('vehicle.car_types')
end

.colorObject


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

def color
  fetch('vehicle.colors')
end

.doorsObject Also known as: door_count


79
80
81
# File 'lib/faker/default/vehicle.rb', line 79

def doors
  sample(fetch_all('vehicle.doors'))
end

.drive_typeObject


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

def drive_type
  fetch('vehicle.drive_types')
end

.engineObject Also known as: engine_size


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

def engine
  "#{sample(fetch_all('vehicle.doors'))} #{fetch('vehicle.cylinder_engine')}"
end

.fuel_typeObject


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

def fuel_type
  fetch('vehicle.fuel_types')
end

.license_plate(state_abreviation = '') ⇒ Object


94
95
96
97
98
99
# File 'lib/faker/default/vehicle.rb', line 94

def license_plate(state_abreviation = '')
  return regexify(bothify(fetch('vehicle.license_plate'))) if state_abreviation.empty?

  key = 'vehicle.license_plate_by_state.' + state_abreviation
  regexify(bothify(fetch(key)))
end

.makeObject


25
26
27
# File 'lib/faker/default/vehicle.rb', line 25

def make
  fetch('vehicle.makes')
end

.make_and_modelObject


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

def make_and_model
  m = make

  "#{m} #{model(m)}"
end

.manufactureObject


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

def manufacture
  fetch('vehicle.manufacture')
end

.mileage(min = MILEAGE_MIN, max = MILEAGE_MAX) ⇒ Object Also known as: kilometrage


88
89
90
# File 'lib/faker/default/vehicle.rb', line 88

def mileage(min = MILEAGE_MIN, max = MILEAGE_MAX)
  rand_in_range(min, max)
end

.model(make_of_model = '') ⇒ Object


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

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

.singapore_license_plateObject


101
102
103
104
105
# File 'lib/faker/default/vehicle.rb', line 101

def singapore_license_plate
  key = 'vehicle.license_plate'
  plate_number = regexify(bothify(fetch(key)))
  "#{plate_number}#{singapore_checksum(plate_number)}"
end

.standard_specsObject


75
76
77
# File 'lib/faker/default/vehicle.rb', line 75

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

.styleObject


41
42
43
# File 'lib/faker/default/vehicle.rb', line 41

def style
  fetch('vehicle.styles')
end

.transmissionObject


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

def transmission
  fetch('vehicle.transmissions')
end

.vinObject


17
18
19
# File 'lib/faker/default/vehicle.rb', line 17

def vin
  regexify(VIN_REGEX)
end

.yearObject


84
85
86
# File 'lib/faker/default/vehicle.rb', line 84

def year
  Faker::Time.backward(rand_in_range(365, 5475), :all, '%Y').to_i
end