vin-validator 1.0.0.pre.rc.4 → 1.1.0.pre.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vin-validator.rb +1 -0
- data/lib/vin_validator/api.rb +0 -3
- data/lib/vin_validator/base_model.rb +31 -0
- data/lib/vin_validator/knowledge.rb +66 -2
- data/lib/vin_validator/maker.rb +8 -15
- data/lib/vin_validator/version.rb +1 -1
- data/lib/vin_validator/wmi.rb +8 -15
- data/lib/vin_validator/year.rb +36 -0
- data/lib/vin_validator/years.json +152 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6523c6bd1ad2fea7e124214d1373e350ad91651425e356895b27fa9e3e65345f
|
4
|
+
data.tar.gz: 8f904a2603046eb4381f417300e0450b0f095aca1c43857de1b9c9753c47bff8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a77c0325d479f4f263e1beb3354cafeb21d6eb7251cba6c7e48f64e735c559c0843fb4d50088c91d910c46002ea234589684b50e7e08edcbb52c4cf943d51a3c
|
7
|
+
data.tar.gz: 90c38e20991bfd30dfc0df5b40eab5c56360d8e1a1e42933482c95af5bb87faacb0df0332b74dd7cd03649df81311393ca1db341aa0a91f901e9c832887a25ef
|
data/lib/vin-validator.rb
CHANGED
data/lib/vin_validator/api.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VinValidator
|
4
|
+
class BaseModel
|
5
|
+
class << self
|
6
|
+
# Loads all objects
|
7
|
+
#
|
8
|
+
# @return [Hash]
|
9
|
+
#
|
10
|
+
def all
|
11
|
+
return @all if defined?(@all)
|
12
|
+
|
13
|
+
all = JSON.parse(File.read(File.join(__dir__, "#{filename}.json")), { symbolize_names: true }).map do |id, v|
|
14
|
+
[id.to_s, new(**v)]
|
15
|
+
end
|
16
|
+
|
17
|
+
@all = all.to_h
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# Basename of the JSON file to read
|
23
|
+
#
|
24
|
+
# @return [String]
|
25
|
+
#
|
26
|
+
def filename
|
27
|
+
''
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -3,11 +3,75 @@
|
|
3
3
|
require_relative './api'
|
4
4
|
require_relative './maker'
|
5
5
|
require_relative './result'
|
6
|
+
require_relative './year'
|
6
7
|
require_relative './wmi'
|
7
8
|
|
8
9
|
module VinValidator
|
9
10
|
class Knowledge
|
10
11
|
class << self
|
12
|
+
# Validates each vin provided
|
13
|
+
#
|
14
|
+
# @param vins [String, Array<String>]
|
15
|
+
# @param hit_nhtsa [Boolean] if `true`, query NHTSA. default: `false`
|
16
|
+
#
|
17
|
+
# @return [Hash]
|
18
|
+
#
|
19
|
+
def validate(vins, hit_nhtsa = false)
|
20
|
+
check_types = {
|
21
|
+
body_type: 'Body type',
|
22
|
+
trailer_type: 'Trailer type',
|
23
|
+
vehicle_type: 'Vehicle type',
|
24
|
+
gvw: 'GVW'
|
25
|
+
}
|
26
|
+
|
27
|
+
results = vin_info(vins, hit_nhtsa).map do |vin, simple_check|
|
28
|
+
unless simple_check.fetch(:errors).empty?
|
29
|
+
next [vin, {
|
30
|
+
valid: false,
|
31
|
+
wmi: [],
|
32
|
+
year: {},
|
33
|
+
errors: simple_check.fetch(:errors).map(&:value)
|
34
|
+
}]
|
35
|
+
end
|
36
|
+
|
37
|
+
vin_split = vin.split('')
|
38
|
+
|
39
|
+
vin_wmi = vin_split[0..2].join
|
40
|
+
vin_year = vin_split[9].to_s
|
41
|
+
year = VinValidator::Year.find_by(letter: vin_year)
|
42
|
+
|
43
|
+
possible_wmis = Array(simple_check[:make]).map { |gem_vin_wmi| { make: gem_vin_wmi.value } }
|
44
|
+
|
45
|
+
errors = []
|
46
|
+
|
47
|
+
if possible_wmis.empty?
|
48
|
+
errors = [
|
49
|
+
'The manufacturer is not a manufacturer of trucking equipment.',
|
50
|
+
'If they are, contact the site admin to add them as a manufacturer.'
|
51
|
+
]
|
52
|
+
end
|
53
|
+
|
54
|
+
infos = []
|
55
|
+
check_types.each do |type, human_type|
|
56
|
+
next if simple_check.dig(type).nil?
|
57
|
+
next if simple_check.fetch(type).value.nil?
|
58
|
+
next if simple_check.fetch(type).value.empty?
|
59
|
+
|
60
|
+
infos << "NHTSA says #{human_type} is #{simple_check.fetch(type).value}"
|
61
|
+
end
|
62
|
+
|
63
|
+
[vin, {
|
64
|
+
valid: !year.nil? && !possible_wmis.nil?,
|
65
|
+
year: { letter: year.letter, year: year.year },
|
66
|
+
errors: errors,
|
67
|
+
wmi: possible_wmis.uniq { |wmi| wmi[:make] },
|
68
|
+
infos: infos
|
69
|
+
}]
|
70
|
+
end
|
71
|
+
|
72
|
+
results.to_h
|
73
|
+
end
|
74
|
+
|
11
75
|
# Gathers/builds info for each vin provided
|
12
76
|
#
|
13
77
|
# @param vins [String, Array<String>]
|
@@ -15,8 +79,8 @@ module VinValidator
|
|
15
79
|
#
|
16
80
|
# @return [Hash]
|
17
81
|
#
|
18
|
-
def vin_info(vins, hit_nhtsa = false
|
19
|
-
results = hit_nhtsa ? VinValidator::Api.vin_info(vins
|
82
|
+
def vin_info(vins, hit_nhtsa = false)
|
83
|
+
results = hit_nhtsa ? VinValidator::Api.vin_info(vins) : {}
|
20
84
|
|
21
85
|
Array(vins).map { |vin| [vin, build_results(vin, results.fetch(vin, {}))] }.to_h
|
22
86
|
end
|
data/lib/vin_validator/maker.rb
CHANGED
@@ -1,22 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module VinValidator
|
4
|
-
class Maker
|
4
|
+
class Maker < VinValidator::BaseModel
|
5
5
|
class << self
|
6
|
-
# Loads all makers
|
7
|
-
#
|
8
|
-
# @return [Hash]
|
9
|
-
#
|
10
|
-
def all
|
11
|
-
return @all if defined?(@all)
|
12
|
-
|
13
|
-
all = JSON.parse(File.read(File.join(__dir__, 'makers.json')), { symbolize_names: true }).map do |id, v|
|
14
|
-
[id.to_s, new(**v)]
|
15
|
-
end
|
16
|
-
|
17
|
-
@all = all.to_h
|
18
|
-
end
|
19
|
-
|
20
6
|
# Finds the maker with the given `id`
|
21
7
|
#
|
22
8
|
# @return [VinValidator::Maker]
|
@@ -24,6 +10,13 @@ module VinValidator
|
|
24
10
|
def find(id)
|
25
11
|
all.fetch(id.to_s)
|
26
12
|
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# @see super
|
17
|
+
def filename
|
18
|
+
'makers'
|
19
|
+
end
|
27
20
|
end
|
28
21
|
|
29
22
|
# @return [Integer]
|
data/lib/vin_validator/wmi.rb
CHANGED
@@ -1,22 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module VinValidator
|
4
|
-
class Wmi
|
4
|
+
class Wmi < VinValidator::BaseModel
|
5
5
|
class << self
|
6
|
-
# Loads all wmis
|
7
|
-
#
|
8
|
-
# @return [Hash]
|
9
|
-
#
|
10
|
-
def all
|
11
|
-
return @all if defined?(@all)
|
12
|
-
|
13
|
-
all = JSON.parse(File.read(File.join(__dir__, 'wmis.json')), { symbolize_names: true }).map do |id, v|
|
14
|
-
[id.to_s, new(**v)]
|
15
|
-
end
|
16
|
-
|
17
|
-
@all = all.to_h
|
18
|
-
end
|
19
|
-
|
20
6
|
# Finds the wmi with the given `id`
|
21
7
|
#
|
22
8
|
# @return [VinValidator::Wmi]
|
@@ -32,6 +18,13 @@ module VinValidator
|
|
32
18
|
def where(wmi:)
|
33
19
|
all.values.select { |w| w.wmi == wmi }
|
34
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# @see super
|
25
|
+
def filename
|
26
|
+
'wmis'
|
27
|
+
end
|
35
28
|
end
|
36
29
|
|
37
30
|
# @return [Integer]
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VinValidator
|
4
|
+
class Year < VinValidator::BaseModel
|
5
|
+
class << self
|
6
|
+
# Finds the year with the given `letter`
|
7
|
+
#
|
8
|
+
# @return [VinValidator::Year]
|
9
|
+
#
|
10
|
+
def find_by(letter:)
|
11
|
+
all.dig(letter.to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# @see super
|
17
|
+
def filename
|
18
|
+
'years'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Integer]
|
23
|
+
attr_accessor :id
|
24
|
+
# @return [Integer]
|
25
|
+
attr_accessor :year
|
26
|
+
# @return [String]
|
27
|
+
attr_accessor :letter
|
28
|
+
|
29
|
+
# :nodoc:
|
30
|
+
def initialize(id:, year:, letter:)
|
31
|
+
@id = id
|
32
|
+
@year = year
|
33
|
+
@letter = letter
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
{
|
2
|
+
"1": {
|
3
|
+
"id": 1,
|
4
|
+
"letter": "1",
|
5
|
+
"year": "2001"
|
6
|
+
},
|
7
|
+
"2": {
|
8
|
+
"id": 2,
|
9
|
+
"letter": "2",
|
10
|
+
"year": "2002"
|
11
|
+
},
|
12
|
+
"3": {
|
13
|
+
"id": 3,
|
14
|
+
"letter": "3",
|
15
|
+
"year": "2003"
|
16
|
+
},
|
17
|
+
"4": {
|
18
|
+
"id": 4,
|
19
|
+
"letter": "4",
|
20
|
+
"year": "2004"
|
21
|
+
},
|
22
|
+
"5": {
|
23
|
+
"id": 5,
|
24
|
+
"letter": "5",
|
25
|
+
"year": "2005"
|
26
|
+
},
|
27
|
+
"6": {
|
28
|
+
"id": 6,
|
29
|
+
"letter": "6",
|
30
|
+
"year": "2006"
|
31
|
+
},
|
32
|
+
"7": {
|
33
|
+
"id": 7,
|
34
|
+
"letter": "7",
|
35
|
+
"year": "2007"
|
36
|
+
},
|
37
|
+
"8": {
|
38
|
+
"id": 8,
|
39
|
+
"letter": "8",
|
40
|
+
"year": "2008"
|
41
|
+
},
|
42
|
+
"9": {
|
43
|
+
"id": 9,
|
44
|
+
"letter": "9",
|
45
|
+
"year": "2009"
|
46
|
+
},
|
47
|
+
"A": {
|
48
|
+
"id": 10,
|
49
|
+
"letter": "A",
|
50
|
+
"year": "2010"
|
51
|
+
},
|
52
|
+
"B": {
|
53
|
+
"id": 11,
|
54
|
+
"letter": "B",
|
55
|
+
"year": "2011"
|
56
|
+
},
|
57
|
+
"C": {
|
58
|
+
"id": 12,
|
59
|
+
"letter": "C",
|
60
|
+
"year": "2012"
|
61
|
+
},
|
62
|
+
"D": {
|
63
|
+
"id": 13,
|
64
|
+
"letter": "D",
|
65
|
+
"year": "2013"
|
66
|
+
},
|
67
|
+
"E": {
|
68
|
+
"id": 14,
|
69
|
+
"letter": "E",
|
70
|
+
"year": "2014"
|
71
|
+
},
|
72
|
+
"F": {
|
73
|
+
"id": 15,
|
74
|
+
"letter": "F",
|
75
|
+
"year": "2015"
|
76
|
+
},
|
77
|
+
"G": {
|
78
|
+
"id": 16,
|
79
|
+
"letter": "G",
|
80
|
+
"year": "2016"
|
81
|
+
},
|
82
|
+
"H": {
|
83
|
+
"id": 17,
|
84
|
+
"letter": "H",
|
85
|
+
"year": "2017"
|
86
|
+
},
|
87
|
+
"J": {
|
88
|
+
"id": 18,
|
89
|
+
"letter": "J",
|
90
|
+
"year": "2018"
|
91
|
+
},
|
92
|
+
"K": {
|
93
|
+
"id": 19,
|
94
|
+
"letter": "K",
|
95
|
+
"year": "2019"
|
96
|
+
},
|
97
|
+
"L": {
|
98
|
+
"id": 20,
|
99
|
+
"letter": "L",
|
100
|
+
"year": "2020"
|
101
|
+
},
|
102
|
+
"M": {
|
103
|
+
"id": 21,
|
104
|
+
"letter": "M",
|
105
|
+
"year": "2021"
|
106
|
+
},
|
107
|
+
"N": {
|
108
|
+
"id": 22,
|
109
|
+
"letter": "N",
|
110
|
+
"year": "2022"
|
111
|
+
},
|
112
|
+
"P": {
|
113
|
+
"id": 23,
|
114
|
+
"letter": "P",
|
115
|
+
"year": "2023"
|
116
|
+
},
|
117
|
+
"R": {
|
118
|
+
"id": 24,
|
119
|
+
"letter": "R",
|
120
|
+
"year": "2024"
|
121
|
+
},
|
122
|
+
"S": {
|
123
|
+
"id": 25,
|
124
|
+
"letter": "S",
|
125
|
+
"year": "1995"
|
126
|
+
},
|
127
|
+
"T": {
|
128
|
+
"id": 26,
|
129
|
+
"letter": "T",
|
130
|
+
"year": "1996"
|
131
|
+
},
|
132
|
+
"V": {
|
133
|
+
"id": 27,
|
134
|
+
"letter": "V",
|
135
|
+
"year": "1997"
|
136
|
+
},
|
137
|
+
"W": {
|
138
|
+
"id": 28,
|
139
|
+
"letter": "W",
|
140
|
+
"year": "1998"
|
141
|
+
},
|
142
|
+
"X": {
|
143
|
+
"id": 29,
|
144
|
+
"letter": "X",
|
145
|
+
"year": "1999"
|
146
|
+
},
|
147
|
+
"Y": {
|
148
|
+
"id": 30,
|
149
|
+
"letter": "Y",
|
150
|
+
"year": "2000"
|
151
|
+
}
|
152
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vin-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0.pre.rc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brands Insurance
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubomatic
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- README.adoc
|
37
37
|
- lib/vin-validator.rb
|
38
38
|
- lib/vin_validator/api.rb
|
39
|
+
- lib/vin_validator/base_model.rb
|
39
40
|
- lib/vin_validator/knowledge.rb
|
40
41
|
- lib/vin_validator/maker.rb
|
41
42
|
- lib/vin_validator/makers.json
|
@@ -43,6 +44,8 @@ files:
|
|
43
44
|
- lib/vin_validator/version.rb
|
44
45
|
- lib/vin_validator/wmi.rb
|
45
46
|
- lib/vin_validator/wmis.json
|
47
|
+
- lib/vin_validator/year.rb
|
48
|
+
- lib/vin_validator/years.json
|
46
49
|
homepage: https://github.com/BrandsInsurance/vin-validator/
|
47
50
|
licenses:
|
48
51
|
- MIT
|