vindetta 0.17.1 → 0.19.0

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
  SHA1:
3
- metadata.gz: dc052c66bde259587a11d28f3b5639872d5e1dc1
4
- data.tar.gz: 52340e3f20255fe4aee6533b6f30038ef970b6b9
3
+ metadata.gz: ef0a0382f394eb885e1ef31017cb92a1176ff84d
4
+ data.tar.gz: abdb80414aab149e380217fae57357c89a99579c
5
5
  SHA512:
6
- metadata.gz: 14306fe4f6bfd2dade7f8e922953336d3fe809908d02fdeb52207b3f476122653197d549d3899d7d63282a083fdbf87a234435ddb2aaaf0b232d0515b6eaf228
7
- data.tar.gz: 9bb861898cb7ba53e2642712c07cc466ce14e91271f99797b6b3665de0fd840adea5b947faaf9d47586a7db5b40cd5925cb4b4976052e78f2deb88b17044e110
6
+ metadata.gz: 67d06d280c0d2f201b124a1923911154f48e8441487340a7e0a47a8553a4713823b4bdd5a7f3f091b555d8e7cc1766a0ad8ec206fefd0dc9c4b3f1b5f78f943b
7
+ data.tar.gz: 96dae041eadc8982a620a1766d7b5d370b4f289167c4ef8cd9f47da29465edc3be525d3241faf38284d58ad49ad61a9103ee7f1b6032f53621dc8e26af083373
data/lib/vindetta/api.rb CHANGED
@@ -3,12 +3,7 @@ require "json"
3
3
 
4
4
  module Vindetta
5
5
  class Api
6
- def self.generate
7
- Net::HTTP.get("randomvin.com", "/getvin.php")
8
-
9
- end
10
-
11
- def self.get(vin)
6
+ def self.decode(vin)
12
7
  uri = URI("https://vpic.nhtsa.dot.gov/api/vehicles/decodevin/#{vin}?format=json")
13
8
 
14
9
  http = Net::HTTP.new(uri.host, uri.port)
@@ -1,15 +1,19 @@
1
1
  module Vindetta
2
2
  class Calculator
3
- MAP = %w(0 1 2 3 4 5 6 7 8 9 X)
3
+ CHECK_DIGITS = "0123456789X".chars
4
4
  WEIGHTS = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2]
5
5
 
6
6
  def self.check_digit(vin)
7
- sum = Transliterator
7
+ CHECK_DIGITS[sum(vin) % CHECK_DIGITS.length]
8
+ end
9
+
10
+ private
11
+
12
+ def self.sum(vin)
13
+ Transliterator
8
14
  .vin(vin)
9
15
  .zip(WEIGHTS)
10
- .reduce(0) {|sum, (a, b)| sum + (a * b) }
11
-
12
- MAP[sum % 11]
16
+ .reduce(0) { |sum, (a, b)| sum + (a * b) }
13
17
  end
14
18
  end
15
19
  end
data/lib/vindetta/cli.rb CHANGED
@@ -11,16 +11,6 @@ module Vindetta
11
11
 
12
12
  program_desc "Vehicle Identification Number (VIN) CLI"
13
13
  version Vindetta::VERSION
14
- error_device = error_device
15
-
16
- desc "Transliterates a VIN character"
17
- arg_name "character"
18
-
19
- command %i[transliterate t] do |c|
20
- c.action do |_global, _options, args|
21
- puts Vindetta::Transliterator.run(args.first)
22
- end
23
- end
24
14
 
25
15
  desc "Validates a VIN"
26
16
 
@@ -50,7 +40,7 @@ module Vindetta
50
40
 
51
41
  command %i[generate g] do |c|
52
42
  c.action do |_global, _options, _args|
53
- puts Vindetta::Generator.generate
43
+ puts Vindetta::Generator.vin
54
44
  end
55
45
  end
56
46
  end
@@ -7,7 +7,7 @@ module Vindetta
7
7
  CHECK_DIGIT_INDEX = 8
8
8
 
9
9
  def self.vin(vin)
10
- Result.new(Api.get(vin)["Results"])
10
+ Result.new(Api.decode(vin)["Results"])
11
11
  end
12
12
 
13
13
  def self.plant_code(vin)
@@ -23,7 +23,7 @@ module Vindetta
23
23
  end
24
24
 
25
25
  def self.vds(vin, options = {})
26
- defaults = { :check_digit => true }
26
+ defaults = { check_digit: true }
27
27
  options = defaults.merge(options)
28
28
 
29
29
  vin[3..CHECK_DIGIT_INDEX].tap do |vds|
@@ -1,29 +1,33 @@
1
1
  module Vindetta
2
2
  class Generator
3
- def self.vin(options = {})
4
- generate(options)
5
- end
3
+ WMI_CHARACTERS = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
4
+ VDS_CHARACTERS = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
5
+ VIS_CHARACTERS = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
6
6
 
7
- def self.generate(_options = {})
8
- fetch
7
+ def self.vin(options = {})
8
+ "#{wmi}#{vds}#{vis}".tap do |vin|
9
+ vin[8] = Calculator.check_digit(vin)
10
+ end
9
11
  end
10
12
 
11
13
  def self.wmi(_options = {})
12
- fetch[0..2]
14
+ WMI_CHARACTERS.sample(3).join("")
13
15
  end
14
16
 
15
17
  def self.vds(_options = {})
16
- fetch[3..8]
18
+ VDS_CHARACTERS.sample(6).join("")
17
19
  end
18
20
 
21
+ ##
22
+ # One consistent element of the VIS is the 10th digit,
23
+ # which is required worldwide to encode the model year of
24
+ # the vehicle. Besides the three letters that are not
25
+ # allowed in the VIN itself (I, O and Q), the letters U
26
+ # and Z and the digit 0 are not used for the model year
27
+ # code. The year code is the model year for the vehicle.
28
+ #
19
29
  def self.vis(_options = {})
20
- fetch[9..16]
21
- end
22
-
23
- private
24
-
25
- def self.fetch(_options = {})
26
- Api.generate
30
+ VIS_CHARACTERS.sample(8).join("")
27
31
  end
28
32
  end
29
33
  end
@@ -1,15 +1,17 @@
1
1
  module Vindetta
2
2
  class Transliterator
3
- MAPPING = "0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ".split("").freeze
3
+ MAPPING = "0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ".chars
4
4
 
5
5
  def self.vin(vin)
6
- vin.chars.map { |c| run(c) }
6
+ vin.chars.map do |c|
7
+ index = MAPPING.find_index(c)
8
+ raise Vindetta::InvalidCharacter, c unless index
9
+ index % 10
10
+ end
7
11
  end
8
12
 
9
13
  def self.run(character)
10
- index = MAPPING.find_index(character)
11
- raise Vindetta::InvalidCharacter, character unless index
12
- index % 10
14
+ vin(character.to_s)[0]
13
15
  end
14
16
  end
15
17
  end
@@ -1,15 +1,25 @@
1
1
  module Vindetta
2
2
  class Validator
3
3
  def self.vin(vin)
4
- length(vin) && check_digit(vin)
4
+ return false unless vin.length == Vindetta::VIN_LENGTH
5
+
6
+ Calculator.check_digit(vin) == Decoder.check_digit(vin)
5
7
  end
6
8
 
7
- def self.length(vin)
8
- vin.length == 17
9
+ def self.wmi(wmi)
10
+ return false unless wmi.length == Vindetta::WMI_LENGTH
9
11
  end
10
12
 
11
- def self.check_digit(vin)
12
- Calculator.check_digit(vin) == Decoder.check_digit(vin)
13
+ def self.vds(vds)
14
+ return false unless vds.length == Vindetta::VDS_LENGTH
15
+
16
+ true
17
+ end
18
+
19
+ def self.vis(vis)
20
+ return false unless vis.length == Vindetta::VIS_LENGTH
21
+
22
+ true
13
23
  end
14
24
  end
15
25
  end
@@ -1,3 +1,3 @@
1
1
  module Vindetta
2
- VERSION = "0.17.1".freeze
2
+ VERSION = "0.19.0".freeze
3
3
  end
data/lib/vindetta.rb CHANGED
@@ -9,7 +9,8 @@ require "vindetta/calculator"
9
9
  require "vindetta/version"
10
10
 
11
11
  module Vindetta
12
- def self.generate(options = {})
13
- Generator.generate(options)
14
- end
12
+ VIN_LENGTH = 17
13
+ WMI_LENGTH = 3
14
+ VDS_LENGTH = 6
15
+ VIS_LENGTH = 8
15
16
  end
data/vindetta.gemspec CHANGED
@@ -1,5 +1,3 @@
1
- # coding: utf-8
2
-
3
1
  lib = File.expand_path("../lib", __FILE__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
  require "vindetta/version"
@@ -28,11 +26,10 @@ Gem::Specification.new do |spec|
28
26
  spec.add_development_dependency "bundler", "~> 1.14"
29
27
  spec.add_development_dependency "factory_bot", "~> 4.8.2"
30
28
  spec.add_development_dependency "guard-rspec", "~> 4.7.3"
31
- spec.add_development_dependency "pry", "~> 0.10"
32
29
  spec.add_development_dependency "rake", "~> 12.3.0"
33
30
  spec.add_development_dependency "rspec", "~> 3.0"
34
31
  spec.add_development_dependency "rubocop", "~> 0.49"
35
- spec.add_development_dependency "webmock", "~> 3.1.1"
36
- spec.add_development_dependency "vcr", "~> 4.0.0"
37
32
  spec.add_development_dependency "simplecov", "~> 0.15.1"
33
+ spec.add_development_dependency "vcr", "~> 4.0.0"
34
+ spec.add_development_dependency "webmock", "~> 3.1.1"
38
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vindetta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.1
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Decot
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-30 00:00:00.000000000 Z
11
+ date: 2018-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 4.7.3
83
- - !ruby/object:Gem::Dependency
84
- name: pry
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0.10'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.10'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rake
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -137,19 +123,19 @@ dependencies:
137
123
  - !ruby/object:Gem::Version
138
124
  version: '0.49'
139
125
  - !ruby/object:Gem::Dependency
140
- name: webmock
126
+ name: simplecov
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
129
  - - "~>"
144
130
  - !ruby/object:Gem::Version
145
- version: 3.1.1
131
+ version: 0.15.1
146
132
  type: :development
147
133
  prerelease: false
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
136
  - - "~>"
151
137
  - !ruby/object:Gem::Version
152
- version: 3.1.1
138
+ version: 0.15.1
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: vcr
155
141
  requirement: !ruby/object:Gem::Requirement
@@ -165,19 +151,19 @@ dependencies:
165
151
  - !ruby/object:Gem::Version
166
152
  version: 4.0.0
167
153
  - !ruby/object:Gem::Dependency
168
- name: simplecov
154
+ name: webmock
169
155
  requirement: !ruby/object:Gem::Requirement
170
156
  requirements:
171
157
  - - "~>"
172
158
  - !ruby/object:Gem::Version
173
- version: 0.15.1
159
+ version: 3.1.1
174
160
  type: :development
175
161
  prerelease: false
176
162
  version_requirements: !ruby/object:Gem::Requirement
177
163
  requirements:
178
164
  - - "~>"
179
165
  - !ruby/object:Gem::Version
180
- version: 0.15.1
166
+ version: 3.1.1
181
167
  description: Ruby gem for generating VINs
182
168
  email:
183
169
  - kyle@joinroot.com