vindetta 0.16.0 → 0.17.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: 8c49fca14fbaabb7d61f5ec8a1407c9d58d49a08
4
- data.tar.gz: fd70297a6f888678684f4ff4fb740695385badee
3
+ metadata.gz: f4f38d44cf4f767c61e1075d998785e2b3db2b24
4
+ data.tar.gz: 5e5a641a4794a50b8189d6c735a07e0f3a8853bb
5
5
  SHA512:
6
- metadata.gz: ec71fe44e68b55b824c9b39de7d169eddc3394367c17e5d2e4c05c89f9bda71121281c1059c53b62650b06c44bafa9f3849c5590a1027a9815db34d7db4e8359
7
- data.tar.gz: c117237631e813aedda91bbb9a13ea8d95b36e331ca889af12d8d4a7fc9cfa07ae8f560f6b0a3541c1602ee8eca26e3217574d2ec2c1dd13f0c1252a1948f483
6
+ metadata.gz: 1893fdec6e3f16ada0960216a114a292088bfaa125e1b2cc9887ab46ae822eb3d3564d84e48a21f75e51bb5545aee80c48f0de49f3259d25714c200cfe906c79
7
+ data.tar.gz: 0d110c315e1ec7fcece6031acd4f9c964567e05b2069db0ca81a944eb33106153135a1da77ce74d3a782c8a54a1bd586fc43a20f2cd4ce7c95e13a2260c6dcea
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ coverage
1
2
  .DS_Store
2
3
  /.bundle/
3
4
  /.yardoc
data/README.md CHANGED
@@ -22,7 +22,25 @@ Or install it yourself as:
22
22
  ## Usage
23
23
 
24
24
  ```bash
25
- $ vindetta generate
25
+ NAME
26
+ vindetta - Vehicle Identification Number (VIN) CLI
27
+
28
+ SYNOPSIS
29
+ vindetta [global options] command [command options] [arguments...]
30
+
31
+ VERSION
32
+ 0.16.0
33
+
34
+ GLOBAL OPTIONS
35
+ --help - Show this message
36
+ --version - Display the program version
37
+
38
+ COMMANDS
39
+ decode, d - Decodes a VIN
40
+ generate, g - Generates a random VIN
41
+ help - Shows a list of commands or help for one command
42
+ transliterate, t - Transliterates a VIN character
43
+ validate, v - Validates a VIN
26
44
  ```
27
45
 
28
46
  ## Development
data/lib/vindetta/api.rb CHANGED
@@ -3,6 +3,11 @@ 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
+
6
11
  def self.get(vin)
7
12
  uri = URI("https://vpic.nhtsa.dot.gov/api/vehicles/decodevin/#{vin}?format=json")
8
13
 
data/lib/vindetta/cli.rb CHANGED
@@ -30,7 +30,7 @@ module Vindetta
30
30
 
31
31
  exit_now!(I18n.t("required"), 1) if vin.nil?
32
32
 
33
- puts Vindetta::Validator.run(vin)
33
+ puts Vindetta::Validator.vin(vin)
34
34
  end
35
35
  end
36
36
 
@@ -42,7 +42,7 @@ module Vindetta
42
42
 
43
43
  exit_now!(I18n.t("required"), 1) if vin.nil?
44
44
 
45
- puts Vindetta::Decoder.decode_vin(vin).to_json
45
+ puts Vindetta::Decoder.vin(vin).to_json
46
46
  end
47
47
  end
48
48
 
@@ -4,7 +4,7 @@ require "json"
4
4
 
5
5
  module Vindetta
6
6
  class Decoder
7
- def self.decode_vin(vin)
7
+ def self.vin(vin)
8
8
  Result.new(Api.get(vin)["Results"])
9
9
  end
10
10
 
@@ -20,12 +20,25 @@ module Vindetta
20
20
  vin[0..2]
21
21
  end
22
22
 
23
- def self.vds(vin)
24
- vin[3..7]
23
+ def self.vds(vin, options = {})
24
+ defaults = { :check_digit => true }
25
+ options = defaults.merge(options)
26
+
27
+ vin[3..8].tap do |vds|
28
+ vds.chop! unless options[:check_digit]
29
+ end
25
30
  end
26
31
 
27
32
  def self.year(vin)
28
- decode_vin(vin).year
33
+ vin(vin).year
34
+ end
35
+
36
+ def self.vis(vin)
37
+ vin[9..16]
38
+ end
39
+
40
+ def self.production_number(vin)
41
+ vin[11..16]
29
42
  end
30
43
  end
31
44
  end
@@ -1,9 +1,29 @@
1
- require "net/http"
2
-
3
1
  module Vindetta
4
2
  class Generator
3
+ def self.vin(options = {})
4
+ generate(options)
5
+ end
6
+
5
7
  def self.generate(_options = {})
6
- Net::HTTP.get("randomvin.com", "/getvin.php")
8
+ fetch
9
+ end
10
+
11
+ def self.wmi(_options = {})
12
+ fetch[0..2]
13
+ end
14
+
15
+ def self.vds(_options = {})
16
+ fetch[3..8]
17
+ end
18
+
19
+ def self.vis(_options = {})
20
+ fetch[9..16]
21
+ end
22
+
23
+ private
24
+
25
+ def self.fetch(_options = {})
26
+ Api.generate
7
27
  end
8
28
  end
9
29
  end
@@ -1,19 +1,21 @@
1
1
  module Vindetta
2
2
  class Validator
3
3
  LENGTH = 17
4
- CHECK_DIGIT_INDEX = 8
5
4
  MAP = "0123456789X".chars
6
- WEIGHTS = "8765432X098765432".chars
5
+ WEIGHTS = "8765432X98765432".chars
7
6
 
8
- def self.run(value)
9
- return false unless value.length == LENGTH
7
+ def self.vin(vin)
8
+ return false unless vin.length == LENGTH
10
9
 
11
- check_digit(value) == value[CHECK_DIGIT_INDEX]
10
+ check_digit(vin) == Decoder.check_digit(vin)
12
11
  end
13
12
 
14
- def self.check_digit(value)
15
- check_digit = value.chars[8]
16
- calculated = value.chars.map.with_index do |c, i|
13
+ def self.check_digit(vin)
14
+ wmi = Decoder.wmi(vin).chars
15
+ vds = Decoder.vds(vin, :check_digit => false).chars
16
+ vis = Decoder.vis(vin).chars
17
+
18
+ calculated = [wmi, vds, vis].flatten.map.with_index do |c, i|
17
19
  Transliterator::run(c) * MAP.find_index(WEIGHTS[i])
18
20
  end.sum
19
21
 
@@ -1,3 +1,3 @@
1
1
  module Vindetta
2
- VERSION = "0.16.0".freeze
2
+ VERSION = "0.17.0".freeze
3
3
  end
data/vindetta.gemspec CHANGED
@@ -34,4 +34,5 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency "rubocop", "~> 0.49"
35
35
  spec.add_development_dependency "webmock", "~> 3.1.1"
36
36
  spec.add_development_dependency "vcr", "~> 4.0.0"
37
+ spec.add_development_dependency "simplecov", "~> 0.15.1"
37
38
  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.16.0
4
+ version: 0.17.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-27 00:00:00.000000000 Z
11
+ date: 2017-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: 4.0.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 0.15.1
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 0.15.1
167
181
  description: Ruby gem for generating VINs
168
182
  email:
169
183
  - kyle@joinroot.com