vindetta 0.17.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vindetta/api.rb +1 -6
- data/lib/vindetta/calculator.rb +9 -5
- data/lib/vindetta/cli.rb +1 -11
- data/lib/vindetta/decoder.rb +2 -2
- data/lib/vindetta/generator.rb +18 -14
- data/lib/vindetta/transliterator.rb +7 -5
- data/lib/vindetta/validator.rb +15 -5
- data/lib/vindetta/version.rb +1 -1
- data/lib/vindetta.rb +4 -3
- data/vindetta.gemspec +2 -5
- metadata +8 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef0a0382f394eb885e1ef31017cb92a1176ff84d
|
4
|
+
data.tar.gz: abdb80414aab149e380217fae57357c89a99579c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67d06d280c0d2f201b124a1923911154f48e8441487340a7e0a47a8553a4713823b4bdd5a7f3f091b555d8e7cc1766a0ad8ec206fefd0dc9c4b3f1b5f78f943b
|
7
|
+
data.tar.gz: 96dae041eadc8982a620a1766d7b5d370b4f289167c4ef8cd9f47da29465edc3be525d3241faf38284d58ad49ad61a9103ee7f1b6032f53621dc8e26af083373
|
data/lib/vindetta/api.rb
CHANGED
@@ -3,12 +3,7 @@ require "json"
|
|
3
3
|
|
4
4
|
module Vindetta
|
5
5
|
class Api
|
6
|
-
def self.
|
7
|
-
Net::HTTP.get("randomvin.com", "/getvin.php")
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.get(vin)
|
6
|
+
def self.decode(vin)
|
12
7
|
uri = URI("https://vpic.nhtsa.dot.gov/api/vehicles/decodevin/#{vin}?format=json")
|
13
8
|
|
14
9
|
http = Net::HTTP.new(uri.host, uri.port)
|
data/lib/vindetta/calculator.rb
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
module Vindetta
|
2
2
|
class Calculator
|
3
|
-
|
3
|
+
CHECK_DIGITS = "0123456789X".chars
|
4
4
|
WEIGHTS = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2]
|
5
5
|
|
6
6
|
def self.check_digit(vin)
|
7
|
-
sum
|
7
|
+
CHECK_DIGITS[sum(vin) % CHECK_DIGITS.length]
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def self.sum(vin)
|
13
|
+
Transliterator
|
8
14
|
.vin(vin)
|
9
15
|
.zip(WEIGHTS)
|
10
|
-
.reduce(0) {|sum, (a, b)| sum + (a * b) }
|
11
|
-
|
12
|
-
MAP[sum % 11]
|
16
|
+
.reduce(0) { |sum, (a, b)| sum + (a * b) }
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
data/lib/vindetta/cli.rb
CHANGED
@@ -11,16 +11,6 @@ module Vindetta
|
|
11
11
|
|
12
12
|
program_desc "Vehicle Identification Number (VIN) CLI"
|
13
13
|
version Vindetta::VERSION
|
14
|
-
error_device = error_device
|
15
|
-
|
16
|
-
desc "Transliterates a VIN character"
|
17
|
-
arg_name "character"
|
18
|
-
|
19
|
-
command %i[transliterate t] do |c|
|
20
|
-
c.action do |_global, _options, args|
|
21
|
-
puts Vindetta::Transliterator.run(args.first)
|
22
|
-
end
|
23
|
-
end
|
24
14
|
|
25
15
|
desc "Validates a VIN"
|
26
16
|
|
@@ -50,7 +40,7 @@ module Vindetta
|
|
50
40
|
|
51
41
|
command %i[generate g] do |c|
|
52
42
|
c.action do |_global, _options, _args|
|
53
|
-
puts Vindetta::Generator.
|
43
|
+
puts Vindetta::Generator.vin
|
54
44
|
end
|
55
45
|
end
|
56
46
|
end
|
data/lib/vindetta/decoder.rb
CHANGED
@@ -7,7 +7,7 @@ module Vindetta
|
|
7
7
|
CHECK_DIGIT_INDEX = 8
|
8
8
|
|
9
9
|
def self.vin(vin)
|
10
|
-
Result.new(Api.
|
10
|
+
Result.new(Api.decode(vin)["Results"])
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.plant_code(vin)
|
@@ -23,7 +23,7 @@ module Vindetta
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.vds(vin, options = {})
|
26
|
-
defaults = { :
|
26
|
+
defaults = { check_digit: true }
|
27
27
|
options = defaults.merge(options)
|
28
28
|
|
29
29
|
vin[3..CHECK_DIGIT_INDEX].tap do |vds|
|
data/lib/vindetta/generator.rb
CHANGED
@@ -1,29 +1,33 @@
|
|
1
1
|
module Vindetta
|
2
2
|
class Generator
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
WMI_CHARACTERS = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
|
4
|
+
VDS_CHARACTERS = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
|
5
|
+
VIS_CHARACTERS = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
|
6
6
|
|
7
|
-
def self.
|
8
|
-
|
7
|
+
def self.vin(options = {})
|
8
|
+
"#{wmi}#{vds}#{vis}".tap do |vin|
|
9
|
+
vin[8] = Calculator.check_digit(vin)
|
10
|
+
end
|
9
11
|
end
|
10
12
|
|
11
13
|
def self.wmi(_options = {})
|
12
|
-
|
14
|
+
WMI_CHARACTERS.sample(3).join("")
|
13
15
|
end
|
14
16
|
|
15
17
|
def self.vds(_options = {})
|
16
|
-
|
18
|
+
VDS_CHARACTERS.sample(6).join("")
|
17
19
|
end
|
18
20
|
|
21
|
+
##
|
22
|
+
# One consistent element of the VIS is the 10th digit,
|
23
|
+
# which is required worldwide to encode the model year of
|
24
|
+
# the vehicle. Besides the three letters that are not
|
25
|
+
# allowed in the VIN itself (I, O and Q), the letters U
|
26
|
+
# and Z and the digit 0 are not used for the model year
|
27
|
+
# code. The year code is the model year for the vehicle.
|
28
|
+
#
|
19
29
|
def self.vis(_options = {})
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def self.fetch(_options = {})
|
26
|
-
Api.generate
|
30
|
+
VIS_CHARACTERS.sample(8).join("")
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
module Vindetta
|
2
2
|
class Transliterator
|
3
|
-
MAPPING = "0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ".
|
3
|
+
MAPPING = "0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ".chars
|
4
4
|
|
5
5
|
def self.vin(vin)
|
6
|
-
vin.chars.map
|
6
|
+
vin.chars.map do |c|
|
7
|
+
index = MAPPING.find_index(c)
|
8
|
+
raise Vindetta::InvalidCharacter, c unless index
|
9
|
+
index % 10
|
10
|
+
end
|
7
11
|
end
|
8
12
|
|
9
13
|
def self.run(character)
|
10
|
-
|
11
|
-
raise Vindetta::InvalidCharacter, character unless index
|
12
|
-
index % 10
|
14
|
+
vin(character.to_s)[0]
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
data/lib/vindetta/validator.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
1
|
module Vindetta
|
2
2
|
class Validator
|
3
3
|
def self.vin(vin)
|
4
|
-
length
|
4
|
+
return false unless vin.length == Vindetta::VIN_LENGTH
|
5
|
+
|
6
|
+
Calculator.check_digit(vin) == Decoder.check_digit(vin)
|
5
7
|
end
|
6
8
|
|
7
|
-
def self.
|
8
|
-
|
9
|
+
def self.wmi(wmi)
|
10
|
+
return false unless wmi.length == Vindetta::WMI_LENGTH
|
9
11
|
end
|
10
12
|
|
11
|
-
def self.
|
12
|
-
|
13
|
+
def self.vds(vds)
|
14
|
+
return false unless vds.length == Vindetta::VDS_LENGTH
|
15
|
+
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.vis(vis)
|
20
|
+
return false unless vis.length == Vindetta::VIS_LENGTH
|
21
|
+
|
22
|
+
true
|
13
23
|
end
|
14
24
|
end
|
15
25
|
end
|
data/lib/vindetta/version.rb
CHANGED
data/lib/vindetta.rb
CHANGED
data/vindetta.gemspec
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
lib = File.expand_path("../lib", __FILE__)
|
4
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
3
|
require "vindetta/version"
|
@@ -28,11 +26,10 @@ Gem::Specification.new do |spec|
|
|
28
26
|
spec.add_development_dependency "bundler", "~> 1.14"
|
29
27
|
spec.add_development_dependency "factory_bot", "~> 4.8.2"
|
30
28
|
spec.add_development_dependency "guard-rspec", "~> 4.7.3"
|
31
|
-
spec.add_development_dependency "pry", "~> 0.10"
|
32
29
|
spec.add_development_dependency "rake", "~> 12.3.0"
|
33
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
31
|
spec.add_development_dependency "rubocop", "~> 0.49"
|
35
|
-
spec.add_development_dependency "webmock", "~> 3.1.1"
|
36
|
-
spec.add_development_dependency "vcr", "~> 4.0.0"
|
37
32
|
spec.add_development_dependency "simplecov", "~> 0.15.1"
|
33
|
+
spec.add_development_dependency "vcr", "~> 4.0.0"
|
34
|
+
spec.add_development_dependency "webmock", "~> 3.1.1"
|
38
35
|
end
|
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.
|
4
|
+
version: 0.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Decot
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 4.7.3
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: pry
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0.10'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0.10'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: rake
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,19 +123,19 @@ dependencies:
|
|
137
123
|
- !ruby/object:Gem::Version
|
138
124
|
version: '0.49'
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
126
|
+
name: simplecov
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
142
128
|
requirements:
|
143
129
|
- - "~>"
|
144
130
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
131
|
+
version: 0.15.1
|
146
132
|
type: :development
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
136
|
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
138
|
+
version: 0.15.1
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: vcr
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,19 +151,19 @@ dependencies:
|
|
165
151
|
- !ruby/object:Gem::Version
|
166
152
|
version: 4.0.0
|
167
153
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
154
|
+
name: webmock
|
169
155
|
requirement: !ruby/object:Gem::Requirement
|
170
156
|
requirements:
|
171
157
|
- - "~>"
|
172
158
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
159
|
+
version: 3.1.1
|
174
160
|
type: :development
|
175
161
|
prerelease: false
|
176
162
|
version_requirements: !ruby/object:Gem::Requirement
|
177
163
|
requirements:
|
178
164
|
- - "~>"
|
179
165
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
166
|
+
version: 3.1.1
|
181
167
|
description: Ruby gem for generating VINs
|
182
168
|
email:
|
183
169
|
- kyle@joinroot.com
|