vin-validator 0.0.4 → 1.0.0.pre.rc.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +1 -1
- data/lib/vin-validator.rb +1 -1
- data/lib/vin_validator/api.rb +4 -1
- data/lib/vin_validator/knowledge.rb +23 -23
- data/lib/vin_validator/maker.rb +8 -4
- data/lib/vin_validator/version.rb +1 -1
- data/lib/vin_validator/wmi.rb +16 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95cf357dcb88d24e42d8a35ff84b597669088179ce1c6c3fe83d6bf888fb8895
|
4
|
+
data.tar.gz: 925575c48c968a5c8acaf1c1ecec242deb9f859437582cb0958667f4e3ee6d55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e516a350da7d1a69f95bdcf9ea560328d5683b7aa54f0b3c3262bfec61e060742212786b7313d1b76daed496b3ab20052b7cf2883cd36fc3a26f4d492ee7b3f5
|
7
|
+
data.tar.gz: d99a387b3c484ab33cbfc16080e7875a6e680e645ca71f5c36cebd5a1b8ae6f9e07fe188ad75bab6f5076a92f5852a0df8541d5d0bd02df344b66f032642b56f
|
data/README.adoc
CHANGED
data/lib/vin-validator.rb
CHANGED
data/lib/vin_validator/api.rb
CHANGED
@@ -14,7 +14,10 @@ module VinValidator
|
|
14
14
|
check_nhtsa = block_given? ? yield : true
|
15
15
|
return {} unless check_nhtsa
|
16
16
|
|
17
|
-
vins_to_check = [vins]
|
17
|
+
vins_to_check = [vins]
|
18
|
+
vins_to_check.flatten!
|
19
|
+
vins_to_check.compact!
|
20
|
+
vins_to_check.uniq!
|
18
21
|
|
19
22
|
api_results =
|
20
23
|
if vins_to_check.size == 1
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative './
|
3
|
+
require_relative './api'
|
4
4
|
require_relative './maker'
|
5
|
+
require_relative './result'
|
5
6
|
require_relative './wmi'
|
6
|
-
require_relative './api'
|
7
7
|
|
8
8
|
module VinValidator
|
9
9
|
class Knowledge
|
@@ -18,10 +18,7 @@ module VinValidator
|
|
18
18
|
def vin_info(vins, hit_nhtsa = false, &block)
|
19
19
|
results = hit_nhtsa ? VinValidator::Api.vin_info(vins, &block) : {}
|
20
20
|
|
21
|
-
Array(vins).
|
22
|
-
vin_results = results.fetch(vin, {})
|
23
|
-
[vin, build_results(vin, vin_results)]
|
24
|
-
end
|
21
|
+
Array(vins).map { |vin| [vin, build_results(vin, results.fetch(vin, {}))] }.to_h
|
25
22
|
end
|
26
23
|
|
27
24
|
private
|
@@ -39,47 +36,48 @@ module VinValidator
|
|
39
36
|
if vin.is_a?(Array)
|
40
37
|
vin.map(&:upcase)
|
41
38
|
else
|
42
|
-
vin.upcase.
|
39
|
+
vin.upcase.chars
|
43
40
|
end
|
44
41
|
|
45
42
|
vin_errors = []
|
46
43
|
|
47
|
-
|
44
|
+
unless vin.join('').match?(/^[a-z0-9]{17}$/i)
|
48
45
|
vin_errors << 'Only numbers and letters are allowed in VINs'
|
49
46
|
end
|
50
47
|
|
51
|
-
|
52
|
-
(0..7).each do |slot|
|
53
|
-
# rubocop:enable Style/EachForSimpleLoop
|
48
|
+
8.times do |slot|
|
54
49
|
# For 1-8, can't have 'I', 'O', or 'Q'
|
55
|
-
if /[ioq]/i
|
50
|
+
if vin[slot].to_s.match?(/[ioq]/i)
|
56
51
|
vin_errors << "'I', 'O', and 'Q' are not allowed in slot #{slot + 1}."
|
57
52
|
end
|
58
53
|
end
|
59
54
|
|
60
|
-
|
55
|
+
# For 9, only 0-9 and 'X' are allowed
|
56
|
+
unless vin[8].to_s.match?(/[0-9x]/i)
|
61
57
|
vin_errors << "Only 0-9 and 'X' are allowed in slot 9."
|
62
58
|
end
|
63
59
|
|
64
|
-
|
60
|
+
# For 10, can't have 'I', 'O', 'Q', 'U', 'Z', '0'
|
61
|
+
if vin[9].to_s.match?(/[iquz0]/i)
|
65
62
|
vin_errors << "'I', 'O', 'Q', 'U', 'Z', and 0 are not allowed in slot 10."
|
66
63
|
end
|
67
64
|
|
68
65
|
(10..13).each do |slot|
|
69
66
|
# For 11-14, can't have 'I', 'O', 'Q'
|
70
|
-
if /[ioq]/i
|
67
|
+
if vin[slot].to_s.match?(/[ioq]/i)
|
71
68
|
vin_errors << "'I', 'O', or 'Q' not allowed in slot #{slot + 1}."
|
72
69
|
end
|
73
70
|
end
|
74
71
|
|
75
72
|
# For 15-17, only 0-9
|
76
73
|
(14..16).each do |slot|
|
77
|
-
unless /[0-9]/i
|
74
|
+
unless vin[slot].to_s.match?(/[0-9]/i)
|
78
75
|
vin_errors << "Only 0-9 allowed in slot #{slot + 1}."
|
79
76
|
end
|
80
77
|
end
|
81
78
|
|
82
|
-
vin_errors << 'Check digit is incorrect.'
|
79
|
+
vin_errors << 'Check digit is incorrect.' if get_check_digit(vin) != vin[8]
|
80
|
+
|
83
81
|
vin_errors
|
84
82
|
end
|
85
83
|
|
@@ -103,13 +101,16 @@ module VinValidator
|
|
103
101
|
map = '0123456789X'
|
104
102
|
weights = '8765432X098765432'
|
105
103
|
sum = 0
|
106
|
-
|
104
|
+
|
105
|
+
17.times do |i|
|
107
106
|
value_weight = transliterate(vin[i])
|
107
|
+
|
108
108
|
return nil if value_weight.nil?
|
109
109
|
|
110
110
|
sum += value_weight * map.index(weights[i])
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
|
+
map[sum % 11]
|
113
114
|
end
|
114
115
|
|
115
116
|
# Combines T2 and NHTSA's results. Will attempt to create `VinValidator::Result`s
|
@@ -143,10 +144,9 @@ module VinValidator
|
|
143
144
|
reset_make ||= vin_results.dig(:make, 0).value.empty?
|
144
145
|
|
145
146
|
if reset_make
|
146
|
-
vin_results[:make] =
|
147
|
-
VinValidator::
|
148
|
-
|
149
|
-
end
|
147
|
+
vin_results[:make] = VinValidator::Wmi.where(wmi: vin.strip[0..2]).map do |wmi|
|
148
|
+
VinValidator::Result.new(vin: vin, type: :make, value: wmi.maker.name)
|
149
|
+
end
|
150
150
|
end
|
151
151
|
|
152
152
|
return vin_results
|
data/lib/vin_validator/maker.rb
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
module VinValidator
|
4
4
|
class Maker
|
5
5
|
class << self
|
6
|
+
# Loads all makers
|
7
|
+
#
|
8
|
+
# @return [Hash]
|
9
|
+
#
|
6
10
|
def all
|
7
11
|
return @all if defined?(@all)
|
8
12
|
|
@@ -11,13 +15,13 @@ module VinValidator
|
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
18
|
+
# Finds the maker with the given `id`
|
19
|
+
#
|
20
|
+
# @return [VinValidator::Maker]
|
21
|
+
#
|
14
22
|
def find(id)
|
15
23
|
all.fetch(id.to_s)
|
16
24
|
end
|
17
|
-
|
18
|
-
def where(wmi:)
|
19
|
-
|
20
|
-
end
|
21
25
|
end
|
22
26
|
|
23
27
|
# @return [Integer]
|
data/lib/vin_validator/wmi.rb
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
module VinValidator
|
4
4
|
class Wmi
|
5
5
|
class << self
|
6
|
+
# Loads all wmis
|
7
|
+
#
|
8
|
+
# @return [Hash]
|
9
|
+
#
|
6
10
|
def all
|
7
11
|
return @all if defined?(@all)
|
8
12
|
|
@@ -11,10 +15,18 @@ module VinValidator
|
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
18
|
+
# Finds the wmi with the given `id`
|
19
|
+
#
|
20
|
+
# @return [VinValidator::Wmi]
|
21
|
+
#
|
14
22
|
def find(id)
|
15
23
|
all.fetch(id.to_s)
|
16
24
|
end
|
17
25
|
|
26
|
+
# Finds the wmi(s) with the given `wmi`
|
27
|
+
#
|
28
|
+
# @return [Array<VinValidator::Wmi>]
|
29
|
+
#
|
18
30
|
def where(wmi:)
|
19
31
|
all.values.select { |w| w.wmi == wmi }
|
20
32
|
end
|
@@ -37,6 +49,10 @@ module VinValidator
|
|
37
49
|
@wmi_suffix = wmi_suffix
|
38
50
|
end
|
39
51
|
|
52
|
+
# Finds the corresponding maker
|
53
|
+
#
|
54
|
+
# @return [VinValidator::Maker]
|
55
|
+
#
|
40
56
|
def maker
|
41
57
|
@maker ||= VinValidator::Maker.find(maker_id)
|
42
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vin-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 1.0.0.pre.rc.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brands Insurance
|
@@ -59,12 +59,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
62
|
+
version: 2.5.3
|
63
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
65
|
+
- - ">"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
67
|
+
version: 1.3.1
|
68
68
|
requirements: []
|
69
69
|
rubygems_version: 3.4.10
|
70
70
|
signing_key:
|