Sha256: 25a31fe22ab54c070b3d0a1e9ea2ef9546226b8f8127687d115534c3cfd91dc3

Contents?: true

Size: 721 Bytes

Versions: 1

Compression:

Stored size: 721 Bytes

Contents

module Vindetta
  class Decoder
    BASE_MODEL_YEAR = 1980
    ALPHA = ('A'..'Z').to_a
    NUMERIC = ("0".."9").to_a

    def initialize(standard)
      @standard = standard
    end

    def vin(vin)
       {
        :plant_code => vin[PLANT_CODE_INDEX],
        :wmi => vin[WMI_RANGE],
        :check_digit => vin[CHECK_DIGIT_INDEX],
        :production_number => vin[PRODUCTION_NUMBER_RANGE],
        :model_year => model_year(vin),
      }
    end

    private

    def model_year(vin)
      index = ((ALPHA - %w[I O Q U Z]) + (NUMERIC - %w[0])).find_index { |c| c == vin[9] }

      if ALPHA.include?(vin[6])
        BASE_MODEL_YEAR + index + 30
      else
        BASE_MODEL_YEAR + index
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vindetta-0.25.0 lib/vindetta/decoder.rb