vindetta 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +19 -1
- data/lib/vindetta/api.rb +5 -0
- data/lib/vindetta/cli.rb +2 -2
- data/lib/vindetta/decoder.rb +17 -4
- data/lib/vindetta/generator.rb +23 -3
- data/lib/vindetta/validator.rb +10 -8
- data/lib/vindetta/version.rb +1 -1
- data/vindetta.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4f38d44cf4f767c61e1075d998785e2b3db2b24
|
4
|
+
data.tar.gz: 5e5a641a4794a50b8189d6c735a07e0f3a8853bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1893fdec6e3f16ada0960216a114a292088bfaa125e1b2cc9887ab46ae822eb3d3564d84e48a21f75e51bb5545aee80c48f0de49f3259d25714c200cfe906c79
|
7
|
+
data.tar.gz: 0d110c315e1ec7fcece6031acd4f9c964567e05b2069db0ca81a944eb33106153135a1da77ce74d3a782c8a54a1bd586fc43a20f2cd4ce7c95e13a2260c6dcea
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -22,7 +22,25 @@ Or install it yourself as:
|
|
22
22
|
## Usage
|
23
23
|
|
24
24
|
```bash
|
25
|
-
|
25
|
+
NAME
|
26
|
+
vindetta - Vehicle Identification Number (VIN) CLI
|
27
|
+
|
28
|
+
SYNOPSIS
|
29
|
+
vindetta [global options] command [command options] [arguments...]
|
30
|
+
|
31
|
+
VERSION
|
32
|
+
0.16.0
|
33
|
+
|
34
|
+
GLOBAL OPTIONS
|
35
|
+
--help - Show this message
|
36
|
+
--version - Display the program version
|
37
|
+
|
38
|
+
COMMANDS
|
39
|
+
decode, d - Decodes a VIN
|
40
|
+
generate, g - Generates a random VIN
|
41
|
+
help - Shows a list of commands or help for one command
|
42
|
+
transliterate, t - Transliterates a VIN character
|
43
|
+
validate, v - Validates a VIN
|
26
44
|
```
|
27
45
|
|
28
46
|
## Development
|
data/lib/vindetta/api.rb
CHANGED
data/lib/vindetta/cli.rb
CHANGED
@@ -30,7 +30,7 @@ module Vindetta
|
|
30
30
|
|
31
31
|
exit_now!(I18n.t("required"), 1) if vin.nil?
|
32
32
|
|
33
|
-
puts Vindetta::Validator.
|
33
|
+
puts Vindetta::Validator.vin(vin)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -42,7 +42,7 @@ module Vindetta
|
|
42
42
|
|
43
43
|
exit_now!(I18n.t("required"), 1) if vin.nil?
|
44
44
|
|
45
|
-
puts Vindetta::Decoder.
|
45
|
+
puts Vindetta::Decoder.vin(vin).to_json
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
data/lib/vindetta/decoder.rb
CHANGED
@@ -4,7 +4,7 @@ require "json"
|
|
4
4
|
|
5
5
|
module Vindetta
|
6
6
|
class Decoder
|
7
|
-
def self.
|
7
|
+
def self.vin(vin)
|
8
8
|
Result.new(Api.get(vin)["Results"])
|
9
9
|
end
|
10
10
|
|
@@ -20,12 +20,25 @@ module Vindetta
|
|
20
20
|
vin[0..2]
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.vds(vin)
|
24
|
-
|
23
|
+
def self.vds(vin, options = {})
|
24
|
+
defaults = { :check_digit => true }
|
25
|
+
options = defaults.merge(options)
|
26
|
+
|
27
|
+
vin[3..8].tap do |vds|
|
28
|
+
vds.chop! unless options[:check_digit]
|
29
|
+
end
|
25
30
|
end
|
26
31
|
|
27
32
|
def self.year(vin)
|
28
|
-
|
33
|
+
vin(vin).year
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.vis(vin)
|
37
|
+
vin[9..16]
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.production_number(vin)
|
41
|
+
vin[11..16]
|
29
42
|
end
|
30
43
|
end
|
31
44
|
end
|
data/lib/vindetta/generator.rb
CHANGED
@@ -1,9 +1,29 @@
|
|
1
|
-
require "net/http"
|
2
|
-
|
3
1
|
module Vindetta
|
4
2
|
class Generator
|
3
|
+
def self.vin(options = {})
|
4
|
+
generate(options)
|
5
|
+
end
|
6
|
+
|
5
7
|
def self.generate(_options = {})
|
6
|
-
|
8
|
+
fetch
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.wmi(_options = {})
|
12
|
+
fetch[0..2]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.vds(_options = {})
|
16
|
+
fetch[3..8]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.vis(_options = {})
|
20
|
+
fetch[9..16]
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def self.fetch(_options = {})
|
26
|
+
Api.generate
|
7
27
|
end
|
8
28
|
end
|
9
29
|
end
|
data/lib/vindetta/validator.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
module Vindetta
|
2
2
|
class Validator
|
3
3
|
LENGTH = 17
|
4
|
-
CHECK_DIGIT_INDEX = 8
|
5
4
|
MAP = "0123456789X".chars
|
6
|
-
WEIGHTS = "
|
5
|
+
WEIGHTS = "8765432X98765432".chars
|
7
6
|
|
8
|
-
def self.
|
9
|
-
return false unless
|
7
|
+
def self.vin(vin)
|
8
|
+
return false unless vin.length == LENGTH
|
10
9
|
|
11
|
-
check_digit(
|
10
|
+
check_digit(vin) == Decoder.check_digit(vin)
|
12
11
|
end
|
13
12
|
|
14
|
-
def self.check_digit(
|
15
|
-
|
16
|
-
|
13
|
+
def self.check_digit(vin)
|
14
|
+
wmi = Decoder.wmi(vin).chars
|
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|
|
17
19
|
Transliterator::run(c) * MAP.find_index(WEIGHTS[i])
|
18
20
|
end.sum
|
19
21
|
|
data/lib/vindetta/version.rb
CHANGED
data/vindetta.gemspec
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.
|
4
|
+
version: 0.17.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: 2017-12-
|
11
|
+
date: 2017-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: 4.0.0
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: simplecov
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 0.15.1
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 0.15.1
|
167
181
|
description: Ruby gem for generating VINs
|
168
182
|
email:
|
169
183
|
- kyle@joinroot.com
|