lib/vindetta/generator.rb in vindetta-0.17.1 vs lib/vindetta/generator.rb in vindetta-0.19.0

- old
+ new

@@ -1,29 +1,33 @@ module Vindetta class Generator + WMI_CHARACTERS = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars + VDS_CHARACTERS = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars + VIS_CHARACTERS = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars + def self.vin(options = {}) - generate(options) + "#{wmi}#{vds}#{vis}".tap do |vin| + vin[8] = Calculator.check_digit(vin) + end end - def self.generate(_options = {}) - fetch - end - def self.wmi(_options = {}) - fetch[0..2] + WMI_CHARACTERS.sample(3).join("") end def self.vds(_options = {}) - fetch[3..8] + VDS_CHARACTERS.sample(6).join("") end + ## + # One consistent element of the VIS is the 10th digit, + # which is required worldwide to encode the model year of + # the vehicle. Besides the three letters that are not + # allowed in the VIN itself (I, O and Q), the letters U + # and Z and the digit 0 are not used for the model year + # code. The year code is the model year for the vehicle. + # def self.vis(_options = {}) - fetch[9..16] - end - - private - - def self.fetch(_options = {}) - Api.generate + VIS_CHARACTERS.sample(8).join("") end end end