Class: NhtsaVin::Validation
- Inherits:
-
Object
- Object
- NhtsaVin::Validation
- Defined in:
- lib/nhtsa_vin/validation.rb
Constant Summary collapse
- TRANSLITERATIONS =
{ 'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6, 'G': 7, 'H': 8, 'J': 1, 'K': 2, 'L': 3, 'M': 4, 'N': 5, 'P': 7, 'R': 9, 'S': 2, 'T': 3, 'U': 4, 'V': 5, 'W': 6, 'X': 7, 'Y': 8, 'Z': 9 }.freeze
- WEIGHTS =
[8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2].freeze
Instance Attribute Summary collapse
-
#check ⇒ Object
readonly
Returns the value of attribute check.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#plant ⇒ Object
readonly
Returns the value of attribute plant.
-
#seq ⇒ Object
readonly
Returns the value of attribute seq.
-
#valid ⇒ Object
readonly
Returns the value of attribute valid.
-
#vds ⇒ Object
readonly
Returns the value of attribute vds.
-
#vin ⇒ Object
readonly
Returns the value of attribute vin.
-
#wmi ⇒ Object
readonly
Returns the value of attribute wmi.
Instance Method Summary collapse
-
#initialize(vin) ⇒ Validation
constructor
Validates a VIN that it fits both the definition, and that the checksum is valid.
- #valid? ⇒ Boolean
Constructor Details
#initialize(vin) ⇒ Validation
Validates a VIN that it fits both the definition, and that the checksum is valid.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nhtsa_vin/validation.rb', line 18 def initialize(vin) @valid = false if vin.nil? @error = 'Blank VIN provided' return end @vin = vin.strip.upcase if !regex @error = 'Invalid VIN format' return elsif checksum != @check @error = "VIN checksum digit #{@check} failed "\ "to calculate (expected #{checksum})" return else @valid = true end end |
Instance Attribute Details
#check ⇒ Object (readonly)
Returns the value of attribute check.
12 13 14 |
# File 'lib/nhtsa_vin/validation.rb', line 12 def check @check end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
12 13 14 |
# File 'lib/nhtsa_vin/validation.rb', line 12 def error @error end |
#plant ⇒ Object (readonly)
Returns the value of attribute plant.
12 13 14 |
# File 'lib/nhtsa_vin/validation.rb', line 12 def plant @plant end |
#seq ⇒ Object (readonly)
Returns the value of attribute seq.
12 13 14 |
# File 'lib/nhtsa_vin/validation.rb', line 12 def seq @seq end |
#valid ⇒ Object (readonly)
Returns the value of attribute valid.
12 13 14 |
# File 'lib/nhtsa_vin/validation.rb', line 12 def valid @valid end |
#vds ⇒ Object (readonly)
Returns the value of attribute vds.
12 13 14 |
# File 'lib/nhtsa_vin/validation.rb', line 12 def vds @vds end |
#vin ⇒ Object (readonly)
Returns the value of attribute vin.
12 13 14 |
# File 'lib/nhtsa_vin/validation.rb', line 12 def vin @vin end |
#wmi ⇒ Object (readonly)
Returns the value of attribute wmi.
12 13 14 |
# File 'lib/nhtsa_vin/validation.rb', line 12 def wmi @wmi end |
Instance Method Details
#valid? ⇒ Boolean
37 38 39 |
# File 'lib/nhtsa_vin/validation.rb', line 37 def valid? @valid end |