Sha256: 82a416404980664192ff8b2c85b24467a7f4da05481ddff9210cfd6d9a96f6ca

Contents?: true

Size: 1020 Bytes

Versions: 7

Compression:

Stored size: 1020 Bytes

Contents

require "active_support"
require "active_model"

module Vindetta
  class Vin
    include ActiveModel::Validations
    include Enumerable

    def each(&block)
      @value.chars(&block)
    end

    def [](index)
      each[index]
    end

    attr_reader :value

    validates_with Validator

    def initialize(value)
      @value = value
    end

    alias eql? ==

    def ==(other)
      self.class == other.class && value == other.value
    end

    def check_digit
      value[8]
    end

    def year
      vis.year
    end

    def region
      wmi.region
    end

    ##
    # World Manufacturer Identity
    #
    def wmi
      @wmi ||= Wmi.new(self)
    end

    # #
    # Vehicle Descriptor Section
    #
    def vds
      @vds ||= Vds.new(self)
    end

    ##
    # Vehicle Identifier Section
    #
    def vis
      @vis ||= Vis.new(self)
    end

    def model_year
      value[9]
    end

    def manufacturing_plant
      value[10]
    end

    def serial_number
      value[11..16]
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vindetta-0.15.0 lib/vindetta/vin.rb
vindetta-0.14.0 lib/vindetta/vin.rb
vindetta-0.13.0 lib/vindetta/vin.rb
vindetta-0.12.0 lib/vindetta/vin.rb
vindetta-0.11.0 lib/vindetta/vin.rb
vindetta-0.10.0 lib/vindetta/vin.rb
vindetta-0.9.0 lib/vindetta/vin.rb