vindetta 0.15.0 → 0.16.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 +24 -0
- data/lib/vindetta/cli.rb +1 -3
- data/lib/vindetta/decoder.rb +22 -4
- data/lib/vindetta/locale/en.yml +1 -0
- data/lib/vindetta/validator.rb +13 -7
- data/lib/vindetta/version.rb +1 -1
- data/lib/vindetta.rb +1 -4
- data/vindetta.gemspec +0 -3
- metadata +3 -45
- data/lib/vindetta/vin.rb +0 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c49fca14fbaabb7d61f5ec8a1407c9d58d49a08
|
4
|
+
data.tar.gz: fd70297a6f888678684f4ff4fb740695385badee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec71fe44e68b55b824c9b39de7d169eddc3394367c17e5d2e4c05c89f9bda71121281c1059c53b62650b06c44bafa9f3849c5590a1027a9815db34d7db4e8359
|
7
|
+
data.tar.gz: c117237631e813aedda91bbb9a13ea8d95b36e331ca889af12d8d4a7fc9cfa07ae8f560f6b0a3541c1602ee8eca26e3217574d2ec2c1dd13f0c1252a1948f483
|
data/lib/vindetta/api.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module Vindetta
|
5
|
+
class Api
|
6
|
+
def self.get(vin)
|
7
|
+
uri = URI("https://vpic.nhtsa.dot.gov/api/vehicles/decodevin/#{vin}?format=json")
|
8
|
+
|
9
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
10
|
+
http.use_ssl = true
|
11
|
+
|
12
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
13
|
+
response = http.request(request)
|
14
|
+
|
15
|
+
parse(http.request(request))
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def self.parse(response)
|
21
|
+
JSON.parse(response.body)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/vindetta/cli.rb
CHANGED
data/lib/vindetta/decoder.rb
CHANGED
@@ -1,13 +1,31 @@
|
|
1
|
-
require "httparty"
|
2
1
|
require "vindetta/decoder/result"
|
2
|
+
require "net/http"
|
3
|
+
require "json"
|
3
4
|
|
4
5
|
module Vindetta
|
5
6
|
class Decoder
|
6
7
|
def self.decode_vin(vin)
|
7
|
-
|
8
|
-
|
8
|
+
Result.new(Api.get(vin)["Results"])
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.plant_code(vin)
|
12
|
+
vin[10]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.check_digit(vin)
|
16
|
+
vin[8]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.wmi(vin)
|
20
|
+
vin[0..2]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.vds(vin)
|
24
|
+
vin[3..7]
|
25
|
+
end
|
9
26
|
|
10
|
-
|
27
|
+
def self.year(vin)
|
28
|
+
decode_vin(vin).year
|
11
29
|
end
|
12
30
|
end
|
13
31
|
end
|
data/lib/vindetta/locale/en.yml
CHANGED
data/lib/vindetta/validator.rb
CHANGED
@@ -1,17 +1,23 @@
|
|
1
|
-
require "active_model"
|
2
|
-
|
3
1
|
module Vindetta
|
4
|
-
class Validator
|
2
|
+
class Validator
|
5
3
|
LENGTH = 17
|
4
|
+
CHECK_DIGIT_INDEX = 8
|
5
|
+
MAP = "0123456789X".chars
|
6
|
+
WEIGHTS = "8765432X098765432".chars
|
6
7
|
|
7
8
|
def self.run(value)
|
8
|
-
|
9
|
+
return false unless value.length == LENGTH
|
10
|
+
|
11
|
+
check_digit(value) == value[CHECK_DIGIT_INDEX]
|
9
12
|
end
|
10
13
|
|
11
|
-
def
|
12
|
-
|
14
|
+
def self.check_digit(value)
|
15
|
+
check_digit = value.chars[8]
|
16
|
+
calculated = value.chars.map.with_index do |c, i|
|
17
|
+
Transliterator::run(c) * MAP.find_index(WEIGHTS[i])
|
18
|
+
end.sum
|
13
19
|
|
14
|
-
|
20
|
+
MAP[calculated % 11]
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
data/lib/vindetta/version.rb
CHANGED
data/lib/vindetta.rb
CHANGED
@@ -3,12 +3,9 @@ require "vindetta/errors"
|
|
3
3
|
require "vindetta/generator"
|
4
4
|
require "vindetta/transliterator"
|
5
5
|
require "vindetta/validator"
|
6
|
+
require "vindetta/api"
|
6
7
|
require "vindetta/decoder"
|
7
8
|
require "vindetta/version"
|
8
|
-
require "vindetta/vin"
|
9
|
-
require "vindetta/vin/wmi"
|
10
|
-
require "vindetta/vin/vds"
|
11
|
-
require "vindetta/vin/vis"
|
12
9
|
|
13
10
|
module Vindetta
|
14
11
|
def self.generate(options = {})
|
data/vindetta.gemspec
CHANGED
@@ -22,11 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
-
spec.add_dependency "activemodel", "~> 5.1"
|
26
|
-
spec.add_dependency "activesupport", "~> 5.1"
|
27
25
|
spec.add_dependency "gli", "~> 2.16"
|
28
26
|
spec.add_dependency "i18n", "~> 0.9.1"
|
29
|
-
spec.add_dependency "httparty", "~> 0.15.6"
|
30
27
|
|
31
28
|
spec.add_development_dependency "bundler", "~> 1.14"
|
32
29
|
spec.add_development_dependency "factory_bot", "~> 4.8.2"
|
metadata
CHANGED
@@ -1,43 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vindetta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.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-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activemodel
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '5.1'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '5.1'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: activesupport
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '5.1'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '5.1'
|
41
13
|
- !ruby/object:Gem::Dependency
|
42
14
|
name: gli
|
43
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,20 +38,6 @@ dependencies:
|
|
66
38
|
- - "~>"
|
67
39
|
- !ruby/object:Gem::Version
|
68
40
|
version: 0.9.1
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: httparty
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 0.15.6
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 0.15.6
|
83
41
|
- !ruby/object:Gem::Dependency
|
84
42
|
name: bundler
|
85
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -227,6 +185,7 @@ files:
|
|
227
185
|
- bin/setup
|
228
186
|
- exe/vindetta
|
229
187
|
- lib/vindetta.rb
|
188
|
+
- lib/vindetta/api.rb
|
230
189
|
- lib/vindetta/cli.rb
|
231
190
|
- lib/vindetta/data/vis.yaml
|
232
191
|
- lib/vindetta/data/wmi.yaml
|
@@ -239,7 +198,6 @@ files:
|
|
239
198
|
- lib/vindetta/transliterator.rb
|
240
199
|
- lib/vindetta/validator.rb
|
241
200
|
- lib/vindetta/version.rb
|
242
|
-
- lib/vindetta/vin.rb
|
243
201
|
- lib/vindetta/vin/vds.rb
|
244
202
|
- lib/vindetta/vin/vis.rb
|
245
203
|
- lib/vindetta/vin/wmi.rb
|
data/lib/vindetta/vin.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
require "active_support"
|
2
|
-
require "active_model"
|
3
|
-
|
4
|
-
module Vindetta
|
5
|
-
class Vin
|
6
|
-
include ActiveModel::Validations
|
7
|
-
include Enumerable
|
8
|
-
|
9
|
-
def each(&block)
|
10
|
-
@value.chars(&block)
|
11
|
-
end
|
12
|
-
|
13
|
-
def [](index)
|
14
|
-
each[index]
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_reader :value
|
18
|
-
|
19
|
-
validates_with Validator
|
20
|
-
|
21
|
-
def initialize(value)
|
22
|
-
@value = value
|
23
|
-
end
|
24
|
-
|
25
|
-
alias eql? ==
|
26
|
-
|
27
|
-
def ==(other)
|
28
|
-
self.class == other.class && value == other.value
|
29
|
-
end
|
30
|
-
|
31
|
-
def check_digit
|
32
|
-
value[8]
|
33
|
-
end
|
34
|
-
|
35
|
-
def year
|
36
|
-
vis.year
|
37
|
-
end
|
38
|
-
|
39
|
-
def region
|
40
|
-
wmi.region
|
41
|
-
end
|
42
|
-
|
43
|
-
##
|
44
|
-
# World Manufacturer Identity
|
45
|
-
#
|
46
|
-
def wmi
|
47
|
-
@wmi ||= Wmi.new(self)
|
48
|
-
end
|
49
|
-
|
50
|
-
# #
|
51
|
-
# Vehicle Descriptor Section
|
52
|
-
#
|
53
|
-
def vds
|
54
|
-
@vds ||= Vds.new(self)
|
55
|
-
end
|
56
|
-
|
57
|
-
##
|
58
|
-
# Vehicle Identifier Section
|
59
|
-
#
|
60
|
-
def vis
|
61
|
-
@vis ||= Vis.new(self)
|
62
|
-
end
|
63
|
-
|
64
|
-
def model_year
|
65
|
-
value[9]
|
66
|
-
end
|
67
|
-
|
68
|
-
def manufacturing_plant
|
69
|
-
value[10]
|
70
|
-
end
|
71
|
-
|
72
|
-
def serial_number
|
73
|
-
value[11..16]
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|