Sha256: 63667df608277de5789385eaf0b1b3d226f7dd4b728277480232375fd8a21ee6

Contents?: true

Size: 658 Bytes

Versions: 3

Compression:

Stored size: 658 Bytes

Contents

module Vindetta
  class Decoder
    def self.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 self.model_year(vin)
      @years ||= YAML.load_file(File.expand_path("../data/vis.yaml", __FILE__))["year"]
      @alpha ||= "ABCDEFGHJKLMNPRSTUVWXYZ".chars

      tenth = vin[9]
      seventh = vin[6]

      if @alpha.include?(seventh)
        @years[tenth].last
      else
        @years[tenth].first
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vindetta-0.23.0 lib/vindetta/decoder.rb
vindetta-0.22.0 lib/vindetta/decoder.rb
vindetta-0.21.0 lib/vindetta/decoder.rb