vin-validator 1.0.0 → 1.1.0.pre.rc.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c3d04d4468c96f8cbed1cf0e44dd34ef3d46fdf263b7fe3ad09c48d90c9224b
4
- data.tar.gz: '09f46ff94ce6201b670e23e0e7b0e7da1a1d9559420f459f280f4202e665b433'
3
+ metadata.gz: d8e5a52d479ddb4dd27dd04bd8f913aaaaea50fee21536ca8bed3062c1ef84b6
4
+ data.tar.gz: 728d00c37bfc36d52cb3d71e9e5ebdcac7fc37a15f704cabd175d095a51f426c
5
5
  SHA512:
6
- metadata.gz: 893b7796831b1b524a0116e252ab5cb4c9ba8d2b16c5c65e15111e02513e373d7eb7fc38bc4adb3ab5594e683dfed9aef6361662a9ed41730623f7f991411a3b
7
- data.tar.gz: a60f59a6b161b07bcce6d0b355f2b96a84376545ae879f55ebb55d3b20d677b6fbebfde52b44e204ac3d8cc53d03d0eaeba49edae705b809f97ba3d5d69085b0
6
+ metadata.gz: f89831b12d70327d1b8cc2b69dee43a09b1b0ae10453117021b45050bc0fdb7a35e7e935e875fccdff806c84f55b54dd56f7f1c138d8a53c1e7ba9fcaf17a78a
7
+ data.tar.gz: 940a7c613399ce02e4a2cd4e24f02ac069ce6869268326134267f86f76fa50b00bc848d9f536cadc265060edc021292b663348bfcbf5d2dc0dbe3d06eed1ec62
data/CHANGELOG.adoc CHANGED
@@ -1,3 +1,8 @@
1
+ = 1.1.0
2
+
3
+ * Added ``VinValidator::Knowledge::validate``
4
+ ** Track revolving 30 years too
5
+
1
6
  = 1.0.0
2
7
 
3
8
  * Intial Release
data/README.adoc CHANGED
@@ -21,6 +21,8 @@ Or install it yourself as:
21
21
 
22
22
  == Usage
23
23
 
24
+ === ``vin_info``
25
+
24
26
  [source,ruby]
25
27
  ----
26
28
  just_a_vin = 'AA5325L1588827'
@@ -86,6 +88,57 @@ Value hash:
86
88
  * ``type`` - The type of result (``error``, ``make``, ``year``, etc)
87
89
  * ``value`` - The value of the result
88
90
 
91
+ === ``validate``
92
+
93
+ [source,ruby]
94
+ ----
95
+ just_a_vin = 'AA5325L1588827'
96
+ other_vins = %w[13N153201K1533942 1E9AA5325L1588827 1RND48A27GR039983 1RND53A33KR049282]
97
+
98
+ VinValidator::Knowledge.validate(just_a_vin).fetch(just_a_vin)
99
+
100
+ VinValidator::Knowledge.validate(just_a_vin, true).fetch(just_a_vin)
101
+
102
+ VinValidator::Knowledge.validate(other_vins)
103
+
104
+ VinValidator::Knowledge.validate(other_vins, true)
105
+ ----
106
+
107
+ Every call to ``VinValidator::Knowledge::vin_info`` will return a hash.
108
+ Each key in the result is one of the VINs provided, and each value is another hash.
109
+
110
+ Value hash:
111
+
112
+ |===
113
+ |Key |Value |Description
114
+
115
+ |``:valid``
116
+ |``Boolean``
117
+ |``false`` if there are errors or year/wmi is blank
118
+
119
+ |``:year``
120
+ |``Hash``, ``Nil``
121
+ |``:letter``(``String``) and ``:year``(``Integer``)
122
+
123
+ |``:wmi``
124
+ |``Array<VinValidator::Result>``
125
+ |Possible makes the VIN can have
126
+
127
+ |``:infos``
128
+ |``Array<String>``
129
+ |The info messages
130
+
131
+ |``:errors``
132
+ |``Array<String>``
133
+ |The error messages
134
+ |===
135
+
136
+ ``VinValidator::Result`` has 3 attributes: ``vin``, ``type``, and ``value``.
137
+
138
+ * ``vin`` - The vin the result belongs to
139
+ * ``type`` - The type of result (``error``, ``make``, ``year``, etc)
140
+ * ``value`` - The value of the result
141
+
89
142
  == Changelog
90
143
 
91
144
  See xref:./CHANGELOG.adoc[CHANGELOG] see changes
data/lib/vin-validator.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
+ require_relative 'vin_validator/base_model'
4
5
  require_relative 'vin_validator/knowledge'
5
6
  require_relative 'vin_validator/version'
6
7
  require 'net/http'
@@ -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,74 @@
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
+ errors: simple_check.fetch(:errors).map(&:value)
33
+ }]
34
+ end
35
+
36
+ vin_split = vin.split('')
37
+
38
+ vin_wmi = vin_split[0..2].join
39
+ vin_year = vin_split[9].to_s
40
+ year = VinValidator::Year.find_by(letter: vin_year)
41
+
42
+ possible_wmis = Array(simple_check[:make])
43
+
44
+ errors = []
45
+
46
+ if possible_wmis.empty?
47
+ errors = [
48
+ 'The manufacturer is not a manufacturer of trucking equipment.',
49
+ 'If they are, contact the site admin to add them as a manufacturer.'
50
+ ]
51
+ end
52
+
53
+ infos = []
54
+ check_types.each do |type, human_type|
55
+ next if simple_check.dig(type).nil?
56
+ next if simple_check.fetch(type).value.nil?
57
+ next if simple_check.fetch(type).value.empty?
58
+
59
+ infos << "NHTSA says #{human_type} is #{simple_check.fetch(type).value}"
60
+ end
61
+
62
+ [vin, {
63
+ valid: !year.nil? && !possible_wmis.empty?,
64
+ year: year,
65
+ errors: errors,
66
+ wmi: possible_wmis.uniq(&:value),
67
+ infos: infos
68
+ }]
69
+ end
70
+
71
+ results.to_h
72
+ end
73
+
11
74
  # Gathers/builds info for each vin provided
12
75
  #
13
76
  # @param vins [String, Array<String>]
@@ -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]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VinValidator
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0-rc.2'
5
5
  end
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vin-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0.pre.rc.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brands Insurance
@@ -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
@@ -62,9 +65,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
65
  version: 2.5.3
63
66
  required_rubygems_version: !ruby/object:Gem::Requirement
64
67
  requirements:
65
- - - ">="
68
+ - - ">"
66
69
  - !ruby/object:Gem::Version
67
- version: '0'
70
+ version: 1.3.1
68
71
  requirements: []
69
72
  rubygems_version: 3.4.10
70
73
  signing_key: