lib/vindetta/vin.rb in vindetta-0.7.0 vs lib/vindetta/vin.rb in vindetta-0.8.0
- old
+ new
@@ -1,15 +1,72 @@
-require 'active_support'
-require 'active_model'
+require "active_support"
+require "active_model"
module Vindetta
class Vin
- attr_reader :value
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
+
+ ##
+ # 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