vin-validator 0.0.3 → 1.0.0.pre.rc.1

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: 38198acef62a76065fc57b5365744bb09b3c85561a7d2b6cbc61ad121caa4585
4
- data.tar.gz: 241fedf88d2f32c952bb86ca5d8052daac1838406cd00aa39bd6a919a5a6eb17
3
+ metadata.gz: '09b6a9a66a5d7d95da1f899f47c76dfce32dfe3c64b0ab9da1430c111ed9f41a'
4
+ data.tar.gz: 1b6ab1b90068a41859ece6ce59a63441f519bf7fc9a0d52279a357a39c071927
5
5
  SHA512:
6
- metadata.gz: 12fb8d34b816c5c1d75462ded857db58cc54bb3de8c544e755968c07666f2f78717209d4212aa731d5cf8cd7e6b6dc4333d8929f3b1675abaafca17ba4525d2a
7
- data.tar.gz: 7e99a3ba78f2e971c653aa4171465cd1de6491be6b1d369a8ca4d77e873d62f10dfde1533f42428a4f0551d64325683a6946544fb822b4c6cccc69bd8937e37e
6
+ metadata.gz: c7dc4990ca5ef305e80aa301ac7e563e65873e2e96c5384768583e320bb27abfa030c3b3c6a7b09caa8ea850251f49b022a64ef7008631a237192a27b100a411
7
+ data.tar.gz: d40e46f343c2cf9fbd1ead1daa5220fabe319ff8ca4352ed7556a9d5df028a81d9e539355a47e5984637f16c81b2c0656c02745396c9a6cc4c5ffd340cca9419
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
@@ -39,42 +39,42 @@ module VinValidator
39
39
  if vin.is_a?(Array)
40
40
  vin.map(&:upcase)
41
41
  else
42
- vin.upcase.split('')
42
+ vin.upcase.chars
43
43
  end
44
44
 
45
45
  vin_errors = []
46
46
 
47
- if vin.join('') !~ /^[a-z0-9]{17}$/i
47
+ unless vin.join('').match?(/^[a-z0-9]{17}$/i)
48
48
  vin_errors << 'Only numbers and letters are allowed in VINs'
49
49
  end
50
50
 
51
- # rubocop:disable Style/EachForSimpleLoop
52
- (0..7).each do |slot|
53
- # rubocop:enable Style/EachForSimpleLoop
51
+ 8.times do |slot|
54
52
  # For 1-8, can't have 'I', 'O', or 'Q'
55
- if /[ioq]/i =~ vin[slot].to_s
53
+ if vin[slot].to_s.match?(/[ioq]/i)
56
54
  vin_errors << "'I', 'O', and 'Q' are not allowed in slot #{slot + 1}."
57
55
  end
58
56
  end
59
57
 
60
- unless /[0-9x]/i =~ vin[8].to_s # For 9, only 0-9 and 'X' are allowed
58
+ # For 9, only 0-9 and 'X' are allowed
59
+ unless vin[8].to_s.match?(/[0-9x]/i)
61
60
  vin_errors << "Only 0-9 and 'X' are allowed in slot 9."
62
61
  end
63
62
 
64
- if /[iquz0]/i =~ vin[9].to_s # For 10, can't have 'I', 'O', 'Q', 'U', 'Z', '0'
63
+ # For 10, can't have 'I', 'O', 'Q', 'U', 'Z', '0'
64
+ if vin[9].to_s.match?(/[iquz0]/i)
65
65
  vin_errors << "'I', 'O', 'Q', 'U', 'Z', and 0 are not allowed in slot 10."
66
66
  end
67
67
 
68
68
  (10..13).each do |slot|
69
69
  # For 11-14, can't have 'I', 'O', 'Q'
70
- if /[ioq]/i =~ vin[slot].to_s
70
+ if vin[slot].to_s.match?(/[ioq]/i)
71
71
  vin_errors << "'I', 'O', or 'Q' not allowed in slot #{slot + 1}."
72
72
  end
73
73
  end
74
74
 
75
75
  # For 15-17, only 0-9
76
76
  (14..16).each do |slot|
77
- unless /[0-9]/i =~ vin[slot].to_s
77
+ unless vin[slot].to_s.match?(/[0-9]/i)
78
78
  vin_errors << "Only 0-9 allowed in slot #{slot + 1}."
79
79
  end
80
80
  end
@@ -103,7 +103,7 @@ module VinValidator
103
103
  map = '0123456789X'
104
104
  weights = '8765432X098765432'
105
105
  sum = 0
106
- (0..16).each do |i|
106
+ 17.times do |i|
107
107
  value_weight = transliterate(vin[i])
108
108
  return nil if value_weight.nil?
109
109
 
@@ -143,10 +143,9 @@ module VinValidator
143
143
  reset_make ||= vin_results.dig(:make, 0).value.empty?
144
144
 
145
145
  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
146
+ vin_results[:make] = VinValidator::Wmi.where(wmi: vin.strip[0..2]).map do |wmi|
147
+ VinValidator::Result.new(vin: vin, type: :make, value: wmi.maker.name)
148
+ end
150
149
  end
151
150
 
152
151
  return vin_results
@@ -3,19 +3,25 @@
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
 
9
- @all = JSON.parse(File.read('makers.json'), { symbolize_names: true }).to_h { |id, v| [id.to_s, new(**v)] }
13
+ @all = JSON.parse(File.read(File.join(__dir__, 'makers.json')), { symbolize_names: true }).to_h do |id, v|
14
+ [id.to_s, new(**v)]
15
+ end
10
16
  end
11
17
 
18
+ # Finds the maker with the given `id`
19
+ #
20
+ # @return [VinValidator::Maker]
21
+ #
12
22
  def find(id)
13
23
  all.fetch(id.to_s)
14
24
  end
15
-
16
- def where(wmi:)
17
-
18
- end
19
25
  end
20
26
 
21
27
  # @return [Integer]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VinValidator
4
- VERSION = '0.0.3'
4
+ VERSION = '1.0.0-rc.1'
5
5
  end
@@ -3,16 +3,30 @@
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
 
9
- @all = JSON.parse(File.read('wmis.json'), { symbolize_names: true }).to_h { |id, v| [id.to_s, new(**v)] }
13
+ @all = JSON.parse(File.read(File.join(__dir__, 'wmis.json')), { symbolize_names: true }).to_h do |id, v|
14
+ [id.to_s, new(**v)]
15
+ end
10
16
  end
11
17
 
18
+ # Finds the wmi with the given `id`
19
+ #
20
+ # @return [VinValidator::Wmi]
21
+ #
12
22
  def find(id)
13
23
  all.fetch(id.to_s)
14
24
  end
15
25
 
26
+ # Finds the wmi(s) with the given `wmi`
27
+ #
28
+ # @return [Array<VinValidator::Wmi>]
29
+ #
16
30
  def where(wmi:)
17
31
  all.values.select { |w| w.wmi == wmi }
18
32
  end
@@ -35,6 +49,10 @@ module VinValidator
35
49
  @wmi_suffix = wmi_suffix
36
50
  end
37
51
 
52
+ # Finds the corresponding maker
53
+ #
54
+ # @return [VinValidator::Maker]
55
+ #
38
56
  def maker
39
57
  @maker ||= VinValidator::Maker.find(maker_id)
40
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.3
4
+ version: 1.0.0.pre.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brands Insurance
@@ -38,11 +38,11 @@ files:
38
38
  - lib/vin_validator/api.rb
39
39
  - lib/vin_validator/knowledge.rb
40
40
  - lib/vin_validator/maker.rb
41
+ - lib/vin_validator/makers.json
41
42
  - lib/vin_validator/result.rb
42
43
  - lib/vin_validator/version.rb
43
44
  - lib/vin_validator/wmi.rb
44
- - makers.json
45
- - wmis.json
45
+ - lib/vin_validator/wmis.json
46
46
  homepage: https://github.com/BrandsInsurance/vin-validator/
47
47
  licenses:
48
48
  - MIT
@@ -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:
File without changes
File without changes