vin_utils 0.1.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +89 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/example +25 -0
- data/bin/setup +8 -0
- data/lib/vin_utils.rb +4 -0
- data/lib/vin_utils/validator.rb +55 -0
- data/lib/vin_utils/version.rb +3 -0
- data/vin_utils.gemspec +27 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c3efe802d6ba3c5d94db3e7c646830c484363a96db6f3ce2d65a2681c2115c44
|
|
4
|
+
data.tar.gz: 73ed8f278fe68109fa66a7bc74142be026cf9be3300d7445632eeb079ee5cf4f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6d87ad1a054f3e98ede2943ba8e1bc883dc995ec2912e1c85e86d310f52d79c0f2ebdb763f4505c0b3350554cf86dea9bd16d43b5a6c36551edb9e2b70ea5415
|
|
7
|
+
data.tar.gz: ad6fa27bcfb837bb7a5c15f55ce9257b2c2597f15dd19f6710cf3b73e294edeb151f65ddd8eabf7fcc06ba3aca2a3085165ed1ccdd2e9b13ce34694466ae633d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Adapted from https://gist.github.com/jhass/a5ae80d87f18e53e7b56
|
|
2
|
+
|
|
3
|
+
AllCops:
|
|
4
|
+
NewCops: enable
|
|
5
|
+
|
|
6
|
+
Layout/LineLength:
|
|
7
|
+
Max: 120
|
|
8
|
+
|
|
9
|
+
Metrics/MethodLength:
|
|
10
|
+
Max: 20
|
|
11
|
+
|
|
12
|
+
Metrics/ClassLength:
|
|
13
|
+
Max: 1500
|
|
14
|
+
|
|
15
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
|
16
|
+
EnforcedStyle: no_space
|
|
17
|
+
|
|
18
|
+
Style/StringLiterals:
|
|
19
|
+
EnforcedStyle: single_quotes
|
|
20
|
+
|
|
21
|
+
Style/SymbolArray:
|
|
22
|
+
Enabled: true
|
|
23
|
+
|
|
24
|
+
Style/HashSyntax:
|
|
25
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
|
26
|
+
|
|
27
|
+
Style/PreferredHashMethods:
|
|
28
|
+
Enabled: false
|
|
29
|
+
|
|
30
|
+
Style/FormatString:
|
|
31
|
+
EnforcedStyle: percent
|
|
32
|
+
|
|
33
|
+
Style/CollectionMethods:
|
|
34
|
+
Enabled: true
|
|
35
|
+
PreferredMethods:
|
|
36
|
+
reduce: "inject"
|
|
37
|
+
|
|
38
|
+
Style/ParenthesesAroundCondition:
|
|
39
|
+
AllowSafeAssignment: false
|
|
40
|
+
Lint/AssignmentInCondition:
|
|
41
|
+
AllowSafeAssignment: false
|
|
42
|
+
|
|
43
|
+
Style/RaiseArgs:
|
|
44
|
+
Enabled: false
|
|
45
|
+
|
|
46
|
+
Layout/MultilineOperationIndentation:
|
|
47
|
+
Enabled: false
|
|
48
|
+
|
|
49
|
+
Style/SignalException:
|
|
50
|
+
EnforcedStyle: only_raise
|
|
51
|
+
|
|
52
|
+
Lint/SuppressedException:
|
|
53
|
+
Enabled: false
|
|
54
|
+
|
|
55
|
+
Layout/SpaceInsideBlockBraces:
|
|
56
|
+
SpaceBeforeBlockParameters: false
|
|
57
|
+
|
|
58
|
+
Layout/SpaceInsideHashLiteralBraces:
|
|
59
|
+
EnforcedStyle: no_space
|
|
60
|
+
|
|
61
|
+
Style/BlockDelimiters:
|
|
62
|
+
Enabled: false
|
|
63
|
+
|
|
64
|
+
Style/MethodCalledOnDoEndBlock:
|
|
65
|
+
Enabled: true
|
|
66
|
+
|
|
67
|
+
Style/SingleLineBlockParams:
|
|
68
|
+
Enabled: false
|
|
69
|
+
|
|
70
|
+
Lint/ShadowingOuterLocalVariable:
|
|
71
|
+
Enabled: false
|
|
72
|
+
|
|
73
|
+
Style/Documentation:
|
|
74
|
+
Enabled: false
|
|
75
|
+
|
|
76
|
+
Naming/BinaryOperatorParameterName:
|
|
77
|
+
Enabled: false
|
|
78
|
+
|
|
79
|
+
Lint/Debugger:
|
|
80
|
+
Enabled: false
|
|
81
|
+
|
|
82
|
+
Style/MethodDefParentheses:
|
|
83
|
+
Enabled: false
|
|
84
|
+
|
|
85
|
+
Style/FrozenStringLiteralComment:
|
|
86
|
+
Enabled: false
|
|
87
|
+
|
|
88
|
+
Metrics/BlockLength:
|
|
89
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
vin_utils (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
diff-lcs (1.4.4)
|
|
10
|
+
rake (12.3.3)
|
|
11
|
+
rspec (3.10.0)
|
|
12
|
+
rspec-core (~> 3.10.0)
|
|
13
|
+
rspec-expectations (~> 3.10.0)
|
|
14
|
+
rspec-mocks (~> 3.10.0)
|
|
15
|
+
rspec-core (3.10.1)
|
|
16
|
+
rspec-support (~> 3.10.0)
|
|
17
|
+
rspec-expectations (3.10.1)
|
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
19
|
+
rspec-support (~> 3.10.0)
|
|
20
|
+
rspec-mocks (3.10.2)
|
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
|
+
rspec-support (~> 3.10.0)
|
|
23
|
+
rspec-support (3.10.2)
|
|
24
|
+
|
|
25
|
+
PLATFORMS
|
|
26
|
+
ruby
|
|
27
|
+
|
|
28
|
+
DEPENDENCIES
|
|
29
|
+
rake (~> 12.0)
|
|
30
|
+
rspec (~> 3.0)
|
|
31
|
+
vin_utils!
|
|
32
|
+
|
|
33
|
+
BUNDLED WITH
|
|
34
|
+
2.1.4
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Diego Stiehl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# VinUtils
|
|
2
|
+
|
|
3
|
+
A gem to check and suggest [VIN](https://en.wikipedia.org/wiki/Vehicle_identification_number) identifiers.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'vin_utils'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle install
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install vin_utils
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
You can use this gem in your code to check the validity of a given VIN.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
input_vin = '11111111111111111'
|
|
27
|
+
validator = VinUtils::Validator.new(input_vin)
|
|
28
|
+
validator.valid? # true
|
|
29
|
+
validator.calculate_check_digit # "1"
|
|
30
|
+
validator.suggest_valid_vin # "11111111111111111"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
> Both `calculate_check_digit` and `suggest_valid_vin` will return `:invalid` incase of an invalid input (invalid characters, size or data type).
|
|
34
|
+
|
|
35
|
+
## Example
|
|
36
|
+
|
|
37
|
+
There is an example console application that can be run by typing:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
bin/example <VIN>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
And it will print to the console something like the example below:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
Provided VIN: <VIN>
|
|
47
|
+
Check Digit: VALID
|
|
48
|
+
This looks like a VALID VIN!
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
require 'vin_utils'
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require 'irb'
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/example
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/vin_utils/validator'
|
|
4
|
+
|
|
5
|
+
if ARGV[0].nil?
|
|
6
|
+
puts 'You must provide a VIN'
|
|
7
|
+
return
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
vin = ARGV[0].to_s
|
|
11
|
+
|
|
12
|
+
validator = VinUtils::Validator.new(vin)
|
|
13
|
+
puts "Provided VIN: #{validator.vin}"
|
|
14
|
+
if validator.valid?
|
|
15
|
+
puts 'Check Digit: VALID'
|
|
16
|
+
puts 'This looks like a VALID VIN!'
|
|
17
|
+
else
|
|
18
|
+
suggested_vin = validator.suggest_valid_vin
|
|
19
|
+
if suggested_vin == :invalid
|
|
20
|
+
puts 'You provided an invalid VIN'
|
|
21
|
+
else
|
|
22
|
+
puts 'Check Digit: INVALID'
|
|
23
|
+
puts "Suggested VIN: #{validator.suggest_valid_vin}"
|
|
24
|
+
end
|
|
25
|
+
end
|
data/bin/setup
ADDED
data/lib/vin_utils.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module VinUtils
|
|
2
|
+
class Validator
|
|
3
|
+
attr_accessor :vin
|
|
4
|
+
|
|
5
|
+
DIGIT_BASE = %w[0 1 2 3 4 5 6 7 8 9 . A B C D E F G H . . J K L M N . P . R . . S T U V W X Y Z].freeze
|
|
6
|
+
MAP = %w[0 1 2 3 4 5 6 7 8 9 X].freeze
|
|
7
|
+
WEIGHTS = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2].freeze
|
|
8
|
+
|
|
9
|
+
def initialize(vin)
|
|
10
|
+
@vin = vin
|
|
11
|
+
@vin = @vin.upcase if @vin.instance_of?(String)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def valid?
|
|
15
|
+
return false unless valid_input?
|
|
16
|
+
|
|
17
|
+
calculate_check_digit == @vin[8]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def calculate_check_digit
|
|
21
|
+
return :invalid unless valid_input?
|
|
22
|
+
|
|
23
|
+
sum = 0
|
|
24
|
+
@vin.chars.each_with_index do |char, i|
|
|
25
|
+
sum += transliterate(char) * WEIGHTS[i]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
MAP[sum % 11]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def suggest_valid_vin
|
|
32
|
+
return :invalid unless valid_input?
|
|
33
|
+
return @vin if valid?
|
|
34
|
+
|
|
35
|
+
new_vin = @vin.dup
|
|
36
|
+
new_vin[8] = calculate_check_digit
|
|
37
|
+
new_vin
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def transliterate(char)
|
|
43
|
+
DIGIT_BASE.index(char) % 10
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def valid_input?
|
|
47
|
+
return false unless @vin.instance_of?(String)
|
|
48
|
+
return false if @vin.chars.size != 17
|
|
49
|
+
|
|
50
|
+
@vin.chars.all? do |char|
|
|
51
|
+
DIGIT_BASE.include?(char) && char != '.'
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
data/vin_utils.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require_relative 'lib/vin_utils/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = 'vin_utils'
|
|
5
|
+
spec.version = VinUtils::VERSION
|
|
6
|
+
spec.authors = ['Diego Stiehl']
|
|
7
|
+
spec.email = ['seccomiro@users.noreply.github.com']
|
|
8
|
+
|
|
9
|
+
spec.summary = 'A gem to check and suggest VIN identifiers'
|
|
10
|
+
spec.description = 'A gem to check and suggest VIN identifiers'
|
|
11
|
+
spec.homepage = 'https://github.com/seccomiro/vin_utils'
|
|
12
|
+
spec.license = 'MIT'
|
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
|
14
|
+
|
|
15
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/seccomiro/vin_utils'
|
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/seccomiro/vin_utils'
|
|
20
|
+
|
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
22
|
+
`git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
|
|
23
|
+
end
|
|
24
|
+
spec.bindir = 'exe'
|
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
|
26
|
+
spec.require_paths = ['lib']
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: vin_utils
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Diego Stiehl
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-02-26 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A gem to check and suggest VIN identifiers
|
|
14
|
+
email:
|
|
15
|
+
- seccomiro@users.noreply.github.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- ".gitignore"
|
|
21
|
+
- ".rspec"
|
|
22
|
+
- ".rubocop.yml"
|
|
23
|
+
- Gemfile
|
|
24
|
+
- Gemfile.lock
|
|
25
|
+
- LICENSE.txt
|
|
26
|
+
- README.md
|
|
27
|
+
- Rakefile
|
|
28
|
+
- bin/console
|
|
29
|
+
- bin/example
|
|
30
|
+
- bin/setup
|
|
31
|
+
- lib/vin_utils.rb
|
|
32
|
+
- lib/vin_utils/validator.rb
|
|
33
|
+
- lib/vin_utils/version.rb
|
|
34
|
+
- vin_utils.gemspec
|
|
35
|
+
homepage: https://github.com/seccomiro/vin_utils
|
|
36
|
+
licenses:
|
|
37
|
+
- MIT
|
|
38
|
+
metadata:
|
|
39
|
+
allowed_push_host: https://rubygems.org
|
|
40
|
+
homepage_uri: https://github.com/seccomiro/vin_utils
|
|
41
|
+
source_code_uri: https://github.com/seccomiro/vin_utils
|
|
42
|
+
changelog_uri: https://github.com/seccomiro/vin_utils
|
|
43
|
+
post_install_message:
|
|
44
|
+
rdoc_options: []
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: 2.4.0
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '0'
|
|
57
|
+
requirements: []
|
|
58
|
+
rubygems_version: 3.1.4
|
|
59
|
+
signing_key:
|
|
60
|
+
specification_version: 4
|
|
61
|
+
summary: A gem to check and suggest VIN identifiers
|
|
62
|
+
test_files: []
|