class Faker::Vehicle
Constants
- MILEAGE_MAX
- MILEAGE_MIN
- SG_CHECKSUM_CHARS
- SG_CHECKSUM_WEIGHTS
- VIN_LETTERS
- VIN_MAP
- VIN_REGEX
- VIN_WEIGHTS
Public Class Methods
car_options()
click to toggle source
# File lib/faker/default/vehicle.rb, line 75 def car_options Array.new(rand(5...10)) { fetch('vehicle.car_options') } end
car_type()
click to toggle source
# File lib/faker/default/vehicle.rb, line 65 def car_type fetch('vehicle.car_types') end
color()
click to toggle source
# File lib/faker/default/vehicle.rb, line 49 def color fetch('vehicle.colors') end
doors()
click to toggle source
# File lib/faker/default/vehicle.rb, line 83 def doors sample(fetch_all('vehicle.doors')) end
Also aliased as: door_count
drive_type()
click to toggle source
# File lib/faker/default/vehicle.rb, line 57 def drive_type fetch('vehicle.drive_types') end
engine()
click to toggle source
# File lib/faker/default/vehicle.rb, line 69 def engine "#{sample(fetch_all('vehicle.doors'))} #{fetch('vehicle.cylinder_engine')}" end
Also aliased as: engine_size
fuel_type()
click to toggle source
# File lib/faker/default/vehicle.rb, line 61 def fuel_type fetch('vehicle.fuel_types') end
kilometrage(legacy_min = NOT_GIVEN, legacy_max = NOT_GIVEN, min: MILEAGE_MIN, max: MILEAGE_MAX)
Alias for: mileage
license_plate(legacy_state_abreviation = NOT_GIVEN, state_abreviation: '')
click to toggle source
# File lib/faker/default/vehicle.rb, line 103 def license_plate(legacy_state_abreviation = NOT_GIVEN, state_abreviation: '') warn_for_deprecated_arguments do |keywords| keywords << :state_abreviation if legacy_state_abreviation != NOT_GIVEN end return regexify(bothify(fetch('vehicle.license_plate'))) if state_abreviation.empty? key = 'vehicle.license_plate_by_state.' + state_abreviation regexify(bothify(fetch(key))) end
make()
click to toggle source
# File lib/faker/default/vehicle.rb, line 25 def make fetch('vehicle.makes') end
make_and_model()
click to toggle source
# File lib/faker/default/vehicle.rb, line 39 def make_and_model m = make "#{m} #{model(make_of_model: m)}" end
manufacture()
click to toggle source
# File lib/faker/default/vehicle.rb, line 21 def manufacture fetch('vehicle.manufacture') end
mileage(legacy_min = NOT_GIVEN, legacy_max = NOT_GIVEN, min: MILEAGE_MIN, max: MILEAGE_MAX)
click to toggle source
# File lib/faker/default/vehicle.rb, line 92 def mileage(legacy_min = NOT_GIVEN, legacy_max = NOT_GIVEN, min: MILEAGE_MIN, max: MILEAGE_MAX) warn_for_deprecated_arguments do |keywords| keywords << :min if legacy_min != NOT_GIVEN keywords << :max if legacy_max != NOT_GIVEN end rand_in_range(min, max) end
Also aliased as: kilometrage
model(legacy_make_of_model = NOT_GIVEN, make_of_model: '')
click to toggle source
# File lib/faker/default/vehicle.rb, line 29 def model(legacy_make_of_model = NOT_GIVEN, make_of_model: '') warn_for_deprecated_arguments do |keywords| keywords << :make_of_model if legacy_make_of_model != NOT_GIVEN end return fetch("vehicle.models_by_make.#{make}") if make_of_model.empty? fetch("vehicle.models_by_make.#{make_of_model}") end
singapore_license_plate()
click to toggle source
# File lib/faker/default/vehicle.rb, line 114 def singapore_license_plate key = 'vehicle.license_plate' plate_number = regexify(bothify(fetch(key))) "#{plate_number}#{singapore_checksum(plate_number)}" end
standard_specs()
click to toggle source
# File lib/faker/default/vehicle.rb, line 79 def standard_specs Array.new(rand(5...10)) { fetch('vehicle.standard_specs') } end
style()
click to toggle source
# File lib/faker/default/vehicle.rb, line 45 def style fetch('vehicle.styles') end
transmission()
click to toggle source
# File lib/faker/default/vehicle.rb, line 53 def transmission fetch('vehicle.transmissions') end
vin()
click to toggle source
# File lib/faker/default/vehicle.rb, line 17 def vin regexify(VIN_REGEX) end
year()
click to toggle source
# File lib/faker/default/vehicle.rb, line 88 def year Faker::Time.backward(days: rand_in_range(365, 5475), period: :all, format: '%Y').to_i end
Private Class Methods
calculate_vin_check_digit(vin)
click to toggle source
# File lib/faker/default/vehicle.rb, line 129 def calculate_vin_check_digit(vin) sum = 0 vin.each_char.with_index do |c, i| n = vin_char_to_number(c).to_i weight = VIN_WEIGHTS[i].to_i sum += weight * n end mod = sum % 11 mod == 10 ? 'X' : mod end
first_eight(number)
click to toggle source
# File lib/faker/default/vehicle.rb, line 122 def first_eight(number) return number[0...8] unless number.nil? regexify(VIN_REGEX) end
Also aliased as: last_eight
singapore_checksum(plate_number)
click to toggle source
# File lib/faker/default/vehicle.rb, line 150 def singapore_checksum(plate_number) padded_alphabets = format('%3s', plate_number[/^[A-Z]+/]).tr(' ', '-').split('') padded_digits = format('%04d', plate_number[/\d+/]).split('').map(&:to_i) sum = [*padded_alphabets, *padded_digits].each_with_index.reduce(0) do |memo, (char, i)| value = char.is_a?(Integer) ? char : char.ord - 64 memo + (SG_CHECKSUM_WEIGHTS[i] * value) end SG_CHECKSUM_CHARS.split('')[sum % 19] end
vin_char_to_number(char)
click to toggle source
# File lib/faker/default/vehicle.rb, line 142 def vin_char_to_number(char) index = VIN_LETTERS.split('').index(char) return char.to_i if index.nil? VIN_MAP[index] end