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

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ddfb8fb532566b001836257182732a1f9f959146dafe564aa9eb9b9f10b8638
4
- data.tar.gz: 6e4fcf5cefc36ec23dc2ca9bc3d754d4e40e8d6837a5519b0df8ad1e616fb588
3
+ metadata.gz: 95cf357dcb88d24e42d8a35ff84b597669088179ce1c6c3fe83d6bf888fb8895
4
+ data.tar.gz: 925575c48c968a5c8acaf1c1ecec242deb9f859437582cb0958667f4e3ee6d55
5
5
  SHA512:
6
- metadata.gz: 77045ee92e5492cd36ae02a334a155e19b3a105645c8bec5d721f2fe0ea6107f587108e8274d1827d687452cf5040fb4ae2fdc2ebc5a478465b41fd8c8683cae
7
- data.tar.gz: cbde65d446fd1801a4797fbd1da2d63033a1e47ec87a1261b3269f8f87e97b06d843ae9eb2d50e4080946ff0167013c41360f28069addf4759cf48cf1cc4d5a0
6
+ metadata.gz: e516a350da7d1a69f95bdcf9ea560328d5683b7aa54f0b3c3262bfec61e060742212786b7313d1b76daed496b3ab20052b7cf2883cd36fc3a26f4d492ee7b3f5
7
+ data.tar.gz: d99a387b3c484ab33cbfc16080e7875a6e680e645ca71f5c36cebd5a1b8ae6f9e07fe188ad75bab6f5076a92f5852a0df8541d5d0bd02df344b66f032642b56f
data/README.adoc CHANGED
@@ -8,7 +8,7 @@ Add this line to your application's Gemfile:
8
8
 
9
9
  [source,ruby]
10
10
  ----
11
- gem 'vin-validator', require: false
11
+ gem 'vin-validator'
12
12
  ----
13
13
 
14
14
  And then execute:
data/lib/vin-validator.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
- require_relative 'vin_validator/version'
5
4
  require_relative 'vin_validator/knowledge'
5
+ require_relative 'vin_validator/version'
6
6
  require 'net/http'
7
7
 
8
8
  module VinValidator
@@ -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].flatten.compact.uniq
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 './result'
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).to_h do |vin|
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.split('')
39
+ vin.upcase.chars
43
40
  end
44
41
 
45
42
  vin_errors = []
46
43
 
47
- if vin.join('') !~ /^[a-z0-9]{17}$/i
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
- # rubocop:disable Style/EachForSimpleLoop
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 =~ vin[slot].to_s
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
- unless /[0-9x]/i =~ vin[8].to_s # For 9, only 0-9 and 'X' are allowed
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
- if /[iquz0]/i =~ vin[9].to_s # For 10, can't have 'I', 'O', 'Q', 'U', 'Z', '0'
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 =~ vin[slot].to_s
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 =~ vin[slot].to_s
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.' unless get_check_digit(vin) == vin[8]
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
- (0..16).each do |i|
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
- return map[sum % 11]
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::Wmi.where(wmi: vin.strip.split('')[0..2].join).map do |wmi|
148
- VinValidator::Result.new(vin: vin, type: :make, value: wmi.maker.name)
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
@@ -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]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VinValidator
4
- VERSION = '0.0.4'
4
+ VERSION = '1.0.0-rc.2'
5
5
  end
@@ -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
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: 3.0.1
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: '0'
67
+ version: 1.3.1
68
68
  requirements: []
69
69
  rubygems_version: 3.4.10
70
70
  signing_key: