lib/vindetta/decoder.rb in vindetta-0.20.0 vs lib/vindetta/decoder.rb in vindetta-0.21.0

- old
+ new

@@ -3,10 +3,27 @@ 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] + :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