vindetta 0.17.0 → 0.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vindetta.rb +1 -0
- data/lib/vindetta/calculator.rb +15 -0
- data/lib/vindetta/decoder.rb +4 -2
- data/lib/vindetta/transliterator.rb +4 -0
- data/lib/vindetta/validator.rb +5 -15
- data/lib/vindetta/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc052c66bde259587a11d28f3b5639872d5e1dc1
|
4
|
+
data.tar.gz: 52340e3f20255fe4aee6533b6f30038ef970b6b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14306fe4f6bfd2dade7f8e922953336d3fe809908d02fdeb52207b3f476122653197d549d3899d7d63282a083fdbf87a234435ddb2aaaf0b232d0515b6eaf228
|
7
|
+
data.tar.gz: 9bb861898cb7ba53e2642712c07cc466ce14e91271f99797b6b3665de0fd840adea5b947faaf9d47586a7db5b40cd5925cb4b4976052e78f2deb88b17044e110
|
data/lib/vindetta.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Vindetta
|
2
|
+
class Calculator
|
3
|
+
MAP = %w(0 1 2 3 4 5 6 7 8 9 X)
|
4
|
+
WEIGHTS = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2]
|
5
|
+
|
6
|
+
def self.check_digit(vin)
|
7
|
+
sum = Transliterator
|
8
|
+
.vin(vin)
|
9
|
+
.zip(WEIGHTS)
|
10
|
+
.reduce(0) {|sum, (a, b)| sum + (a * b) }
|
11
|
+
|
12
|
+
MAP[sum % 11]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/vindetta/decoder.rb
CHANGED
@@ -4,6 +4,8 @@ require "json"
|
|
4
4
|
|
5
5
|
module Vindetta
|
6
6
|
class Decoder
|
7
|
+
CHECK_DIGIT_INDEX = 8
|
8
|
+
|
7
9
|
def self.vin(vin)
|
8
10
|
Result.new(Api.get(vin)["Results"])
|
9
11
|
end
|
@@ -13,7 +15,7 @@ module Vindetta
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def self.check_digit(vin)
|
16
|
-
vin[
|
18
|
+
vin[CHECK_DIGIT_INDEX]
|
17
19
|
end
|
18
20
|
|
19
21
|
def self.wmi(vin)
|
@@ -24,7 +26,7 @@ module Vindetta
|
|
24
26
|
defaults = { :check_digit => true }
|
25
27
|
options = defaults.merge(options)
|
26
28
|
|
27
|
-
vin[3..
|
29
|
+
vin[3..CHECK_DIGIT_INDEX].tap do |vds|
|
28
30
|
vds.chop! unless options[:check_digit]
|
29
31
|
end
|
30
32
|
end
|
@@ -2,6 +2,10 @@ module Vindetta
|
|
2
2
|
class Transliterator
|
3
3
|
MAPPING = "0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ".split("").freeze
|
4
4
|
|
5
|
+
def self.vin(vin)
|
6
|
+
vin.chars.map { |c| run(c) }
|
7
|
+
end
|
8
|
+
|
5
9
|
def self.run(character)
|
6
10
|
index = MAPPING.find_index(character)
|
7
11
|
raise Vindetta::InvalidCharacter, character unless index
|
data/lib/vindetta/validator.rb
CHANGED
@@ -1,25 +1,15 @@
|
|
1
1
|
module Vindetta
|
2
2
|
class Validator
|
3
|
-
LENGTH = 17
|
4
|
-
MAP = "0123456789X".chars
|
5
|
-
WEIGHTS = "8765432X98765432".chars
|
6
|
-
|
7
3
|
def self.vin(vin)
|
8
|
-
|
4
|
+
length(vin) && check_digit(vin)
|
5
|
+
end
|
9
6
|
|
10
|
-
|
7
|
+
def self.length(vin)
|
8
|
+
vin.length == 17
|
11
9
|
end
|
12
10
|
|
13
11
|
def self.check_digit(vin)
|
14
|
-
|
15
|
-
vds = Decoder.vds(vin, :check_digit => false).chars
|
16
|
-
vis = Decoder.vis(vin).chars
|
17
|
-
|
18
|
-
calculated = [wmi, vds, vis].flatten.map.with_index do |c, i|
|
19
|
-
Transliterator::run(c) * MAP.find_index(WEIGHTS[i])
|
20
|
-
end.sum
|
21
|
-
|
22
|
-
MAP[calculated % 11]
|
12
|
+
Calculator.check_digit(vin) == Decoder.check_digit(vin)
|
23
13
|
end
|
24
14
|
end
|
25
15
|
end
|
data/lib/vindetta/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vindetta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.17.
|
4
|
+
version: 0.17.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Decot
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|
@@ -200,6 +200,7 @@ files:
|
|
200
200
|
- exe/vindetta
|
201
201
|
- lib/vindetta.rb
|
202
202
|
- lib/vindetta/api.rb
|
203
|
+
- lib/vindetta/calculator.rb
|
203
204
|
- lib/vindetta/cli.rb
|
204
205
|
- lib/vindetta/data/vis.yaml
|
205
206
|
- lib/vindetta/data/wmi.yaml
|