vin-validator 0.0.4 → 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: 0ddfb8fb532566b001836257182732a1f9f959146dafe564aa9eb9b9f10b8638
4
- data.tar.gz: 6e4fcf5cefc36ec23dc2ca9bc3d754d4e40e8d6837a5519b0df8ad1e616fb588
3
+ metadata.gz: '09b6a9a66a5d7d95da1f899f47c76dfce32dfe3c64b0ab9da1430c111ed9f41a'
4
+ data.tar.gz: 1b6ab1b90068a41859ece6ce59a63441f519bf7fc9a0d52279a357a39c071927
5
5
  SHA512:
6
- metadata.gz: 77045ee92e5492cd36ae02a334a155e19b3a105645c8bec5d721f2fe0ea6107f587108e8274d1827d687452cf5040fb4ae2fdc2ebc5a478465b41fd8c8683cae
7
- data.tar.gz: cbde65d446fd1801a4797fbd1da2d63033a1e47ec87a1261b3269f8f87e97b06d843ae9eb2d50e4080946ff0167013c41360f28069addf4759cf48cf1cc4d5a0
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,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.1'
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.1
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: