vindetta 0.24.0 → 0.25.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: ad6e970871eb591e0f430b78fe2940201dedd0e7
4
- data.tar.gz: 38c7548b9a5a98507205f998176db995f659aa35
3
+ metadata.gz: 3dbbe61deb1b5f0e99e9008cf72c6245fd4dbd0c
4
+ data.tar.gz: fcd8b4049b037d0f9b6d3014982ebe5f6be94b10
5
5
  SHA512:
6
- metadata.gz: d29396ef25dfea7edde00fecfe8ea48f0497f0ddb9a041da5bab0f24df4213c1b1f68fe1133c8250b8002f3fea269afd30f604959584f79009337c477c7b792e
7
- data.tar.gz: 96872e1404a6ec1d0863cb0ba5d2e5966db0dde38e4b837274829fc74a14f232a862ca4a35caf87b9f307abf2d93d1637b8f5d63f70ee986438b5fd35da7a647
6
+ metadata.gz: fed19a59cae3e7a4ccafbeeac0b723efc82671ddef1b391a9d80af0d2ed5d03578ee4a27a6dad7200b3cd2b9cd9c2820e927037174dc859aae1db62703a75244
7
+ data.tar.gz: 64b175741142d7f8f1ff645fab7e573a4677e777cce29731585e69a69b2c687f7a670491e689acd2cf5e2c1793eb922ba557b232537bf4ced7ecbd0c0e1d7b7f
@@ -2,20 +2,14 @@ require "vindetta/calculator"
2
2
  require "vindetta/cli"
3
3
  require "vindetta/decoder"
4
4
  require "vindetta/generator"
5
+ require "vindetta/standard"
5
6
  require "vindetta/validator"
6
7
  require "vindetta/version"
7
8
 
8
9
  module Vindetta
9
- VIN_LENGTH = 17
10
- WMI_LENGTH = 3
11
- VDS_LENGTH = 6
12
- VIS_LENGTH = 8
13
-
14
10
  CHECK_DIGIT_INDEX = 8
15
11
  PLANT_CODE_INDEX = 10
16
12
 
17
- WMI_CHARACTERS = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
18
- VDS_CHARACTERS = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
19
13
  VIS_CHARACTERS = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
20
14
  MODEL_YEAR_CHARACTERS = VIS_CHARACTERS - "UZ".chars
21
15
 
@@ -13,14 +13,17 @@ module Vindetta
13
13
  version Vindetta::VERSION
14
14
 
15
15
  desc "Validates a VIN"
16
-
16
+
17
17
  command %i[validate v] do |c|
18
18
  c.action do |_global, _options, args|
19
19
  vin = args.first
20
20
 
21
21
  exit_now!(I18n.t("required"), 1) if vin.nil?
22
22
 
23
- puts Vindetta::Validator.vin(vin)
23
+ standard = Vindetta::Standard::ISO3779
24
+ validator = Vindetta::Validator.new(standard)
25
+
26
+ puts validator.vin(vin)
24
27
  end
25
28
  end
26
29
 
@@ -32,7 +35,10 @@ module Vindetta
32
35
 
33
36
  exit_now!(I18n.t("required"), 1) if vin.nil?
34
37
 
35
- puts Vindetta::Decoder.vin(vin)
38
+ standard = Vindetta::Standard::ISO3779
39
+ decoder = Vindetta::Decoder.new(standard)
40
+
41
+ puts decoder.vin(vin)
36
42
  end
37
43
  end
38
44
 
@@ -40,7 +46,10 @@ module Vindetta
40
46
 
41
47
  command %i[generate g] do |c|
42
48
  c.action do |_global, _options, _args|
43
- puts Vindetta::Generator.vin
49
+ standard = Vindetta::Standard::ISO3779
50
+ generator = Vindetta::Generator.new(standard)
51
+
52
+ puts generator.vin
44
53
  end
45
54
  end
46
55
  end
@@ -4,8 +4,12 @@ module Vindetta
4
4
  ALPHA = ('A'..'Z').to_a
5
5
  NUMERIC = ("0".."9").to_a
6
6
 
7
- def self.vin(vin)
8
- {
7
+ def initialize(standard)
8
+ @standard = standard
9
+ end
10
+
11
+ def vin(vin)
12
+ {
9
13
  :plant_code => vin[PLANT_CODE_INDEX],
10
14
  :wmi => vin[WMI_RANGE],
11
15
  :check_digit => vin[CHECK_DIGIT_INDEX],
@@ -16,7 +20,7 @@ module Vindetta
16
20
 
17
21
  private
18
22
 
19
- def self.model_year(vin)
23
+ def model_year(vin)
20
24
  index = ((ALPHA - %w[I O Q U Z]) + (NUMERIC - %w[0])).find_index { |c| c == vin[9] }
21
25
 
22
26
  if ALPHA.include?(vin[6])
@@ -1,29 +1,36 @@
1
1
  module Vindetta
2
2
  class Generator
3
- def self.vin(options = {})
3
+ attr_reader :standard
4
+
5
+ def initialize(standard)
6
+ @standard = standard
7
+ end
8
+
9
+ def vin(options = {})
4
10
  "#{wmi}#{vds}#{vis}".tap do |vin|
5
11
  vin[CHECK_DIGIT_INDEX] = Calculator.check_digit(vin)
6
12
  end
7
13
  end
8
14
 
9
- def self.wmi(_options = {})
15
+ def wmi(_options = {})
10
16
  @wmis ||= begin
11
17
  path = File.expand_path("../data/wmi.yaml", __FILE__)
12
18
  YAML.load_file(path)["wmi"].keys
13
19
  end
14
20
 
15
- "#{@wmis.sample}".rjust(WMI_LENGTH, "9")
21
+ "#{@wmis.sample}".rjust(standard.wmi.length, "9")
16
22
  end
17
23
 
18
- def self.vds(_options = {})
19
- VDS_CHARACTERS.sample(VDS_LENGTH).join("")
24
+ def vds(_options = {})
25
+ characters = standard.vds.map(&:characters)
26
+
27
+ characters.map(&:sample).join
20
28
  end
21
29
 
22
- def self.vis(_options = {})
23
- [
24
- MODEL_YEAR_CHARACTERS.sample,
25
- VIS_CHARACTERS.sample(VIS_LENGTH - 1)
26
- ].flatten.join("")
30
+ def vis(_options = {})
31
+ characters = standard.vis.map(&:characters)
32
+
33
+ characters.map(&:sample).join
27
34
  end
28
35
  end
29
36
  end
@@ -0,0 +1,6 @@
1
+ require 'vindetta/standard/iso3779'
2
+
3
+ module Vindetta
4
+ module Standard
5
+ end
6
+ end
@@ -0,0 +1,65 @@
1
+ module Vindetta
2
+ module Standard
3
+ class ISO3779
4
+ LENGTH = 17
5
+
6
+ def self.wmi
7
+ OpenStruct.new(
8
+ :length => 3
9
+ )
10
+ end
11
+
12
+ def self.vds
13
+ @vds ||= [
14
+ OpenStruct.new({
15
+ :characters => "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
16
+ }),
17
+ OpenStruct.new({
18
+ :characters => "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
19
+ }),
20
+ OpenStruct.new({
21
+ :characters => "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
22
+ }),
23
+ OpenStruct.new({
24
+ :characters => "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
25
+ }),
26
+ OpenStruct.new({
27
+ :characters => "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
28
+ }),
29
+ OpenStruct.new({
30
+ :characters => "0123456789ABCDEFGHJKLMNPRSTUVWXYZ".chars
31
+ })
32
+ ]
33
+ end
34
+
35
+ def self.vis
36
+ @vis ||= [
37
+ OpenStruct.new({
38
+ :characters => ["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", "V", "W", "X", "Y"]
39
+ }),
40
+ OpenStruct.new({
41
+ :characters => ["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"]
42
+ }),
43
+ OpenStruct.new({
44
+ :characters => ["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"]
45
+ }),
46
+ OpenStruct.new({
47
+ :characters => ["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"]
48
+ }),
49
+ OpenStruct.new({
50
+ :characters => ["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"]
51
+ }),
52
+ OpenStruct.new({
53
+ :characters => ["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"]
54
+ }),
55
+ OpenStruct.new({
56
+ :characters => ["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"]
57
+ }),
58
+ OpenStruct.new({
59
+ :characters => ["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"]
60
+ })
61
+ ]
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,27 +1,33 @@
1
1
  module Vindetta
2
2
  class Validator
3
- def self.vin(vin)
4
- return false unless vin.length == Vindetta::VIN_LENGTH
3
+ attr_reader :standard
5
4
 
6
- Calculator.check_digit(vin) == Decoder.vin(vin)[:check_digit]
5
+ def initialize(standard)
6
+ @standard = standard
7
+ end
8
+
9
+ def vin(vin)
10
+ return false unless vin.length == standard::LENGTH
11
+
12
+ Calculator.check_digit(vin) == Decoder.new(Vindetta::Standard::ISO3779).vin(vin)[:check_digit]
7
13
  rescue Calculator::InvalidCharacterError
8
14
  false
9
15
  end
10
16
 
11
- def self.wmi(wmi)
12
- return false unless wmi.length == Vindetta::WMI_LENGTH
17
+ def wmi(wmi)
18
+ return false unless wmi.length == standard.wmi.length
13
19
 
14
20
  true
15
21
  end
16
22
 
17
- def self.vds(vds)
18
- return false unless vds.length == Vindetta::VDS_LENGTH
23
+ def vds(vds)
24
+ return false unless vds.length == standard.vds.length
19
25
 
20
26
  true
21
27
  end
22
28
 
23
- def self.vis(vis)
24
- return false unless vis.length == Vindetta::VIS_LENGTH
29
+ def vis(vis)
30
+ return false unless vis.length == standard.vis.length
25
31
 
26
32
  true
27
33
  end
@@ -1,3 +1,3 @@
1
1
  module Vindetta
2
- VERSION = "0.24.0".freeze
2
+ VERSION = "0.25.0".freeze
3
3
  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.24.0
4
+ version: 0.25.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: 2018-07-30 00:00:00.000000000 Z
11
+ date: 2018-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -165,6 +165,8 @@ files:
165
165
  - lib/vindetta/decoder.rb
166
166
  - lib/vindetta/generator.rb
167
167
  - lib/vindetta/locale/en.yml
168
+ - lib/vindetta/standard.rb
169
+ - lib/vindetta/standard/iso3779.rb
168
170
  - lib/vindetta/validator.rb
169
171
  - lib/vindetta/version.rb
170
172
  - vindetta.gemspec