vinbot 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8d7d9bc70a337ff3bfaf9ca8efde07268cabb0be
4
+ data.tar.gz: 9cefd45d2872c8e5db992851f2456ba64daa52b4
5
+ SHA512:
6
+ metadata.gz: 89b34b5a9fa7ea796492cfd576e8fbbc31ba08f63df45b2ad60f3e5ad76f26c11c3e83cc74cba2ba0cb68adbdf83ce963331aa856f12f5d67fce7a151b4ecfaf
7
+ data.tar.gz: ada02084a4201351ec72be334a99e421f32ab188b29bdca99b6aa55a0202baad7722ad865a58c0c6114cfabae070533dddba2541b2c26bddc67195b6cfbf1bd5
@@ -0,0 +1,7 @@
1
+ module Vinbot
2
+ module Data
3
+ class BodyType < Sequel::Model
4
+ one_to_many :vehicles
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module Vinbot
2
+ module Data
3
+ class Constants
4
+
5
+ WEIGHT_FACTORS = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2]
6
+
7
+ EBCDIC_MAP = {'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'J' => 1, 'K' => 2,
8
+ 'L' => 3, 'M' => 4, 'N' => 5, 'P' => 7, 'R' => 9, 'S' => 2, 'T' => 3, 'U' => 4, 'V' => 5, 'W' => 6,
9
+ 'X' => 7, 'Y' => 8, 'Z' => 9}
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ module Vinbot
2
+ module Data
3
+ class Drivetrain < Sequel::Model
4
+ one_to_many :vehicles
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Vinbot
2
+ module Data
3
+ class EngineType < Sequel::Model
4
+ one_to_many :vehicles
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Vinbot
2
+ module Data
3
+ class ExteriorColor < Sequel::Model
4
+ one_to_many :vehicles
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Vinbot
2
+ module Data
3
+ class InteriorColor < Sequel::Model
4
+ one_to_many :vehicles
5
+ end
6
+ end
7
+ end
data/lib/data/make.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Vinbot
2
+ module Data
3
+ class Make < Sequel::Model
4
+ one_to_many :vehicles
5
+ end
6
+ end
7
+ end
data/lib/data/model.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Vinbot
2
+ module Data
3
+ class Model < Sequel::Model
4
+ one_to_many :vehicles
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Vinbot
2
+ module Data
3
+ class Transmission < Sequel::Model
4
+ one_to_many :vehicles
5
+ end
6
+ end
7
+ end
data/lib/data/trim.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Vinbot
2
+ module Data
3
+ class Trim < Sequel::Model
4
+ one_to_many :vehicles
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module Vinbot
2
+ module Data
3
+ class Vehicle < Sequel::Model
4
+ many_to_one :year
5
+ many_to_one :make
6
+ many_to_one :model
7
+ many_to_one :trim
8
+ many_to_one :body_type
9
+ many_to_one :drivetrain
10
+ many_to_one :engine_type
11
+ many_to_one :exterior_color
12
+ many_to_one :interior_color
13
+ many_to_one :transmission
14
+ many_to_one :vehicle_type
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module Vinbot
2
+ module Data
3
+ class VehicleType < Sequel::Model
4
+ one_to_many :vehicles
5
+ end
6
+ end
7
+ end
data/lib/data/year.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Vinbot
2
+ module Data
3
+ class Year < Sequel::Model
4
+ one_to_many :vehicles
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ module Vinbot
2
+ class Vehicle
3
+
4
+ attr_accessor :year, :make, :model, :trim, :engine_type, :transmission, :body_type, :vehicle_type, :drivetrain,
5
+ :interior_colors, :exterior_colors, :vin
6
+
7
+ def initialize
8
+ vehicle = ::Vinbot::Data::Vehicle.order(Sequel.lit('RANDOM()')).limit(1).first
9
+ @year = vehicle.year.name
10
+ @make = vehicle.make.name
11
+ @model = vehicle.model.name
12
+ @trim = vehicle.trim.name
13
+ @engine_type = vehicle.engine_type.name
14
+ @transmission = vehicle.transmission.name
15
+ @body_type = vehicle.body_type.name
16
+ @vehicle_type = vehicle.vehicle_type.name
17
+ @drivetrain = vehicle.drivetrain.name
18
+ @interior_colors = vehicle.interior_color.name.split(',')
19
+ @exterior_colors = vehicle.exterior_color.name.split(',')
20
+ @vin = Vin.generate_from_partial_vin(vehicle.partial_vin)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Vinbot
2
+ VERSION = "2.0.0"
3
+ end
data/lib/vinbot/vin.rb ADDED
@@ -0,0 +1,48 @@
1
+ module Vinbot
2
+ class Vin
3
+
4
+ class << self
5
+
6
+ def generate
7
+ Vinbot::Vehicle.new.vin
8
+ end
9
+
10
+ def generate_from_partial_vin(partial_vin)
11
+ vin_digits = partial_vin.chars.to_a.insert(8, '_')
12
+ vin_digits += serial
13
+ vin_digits[8] = calculate_check_digit(vin_digits)
14
+ vin_digits.join
15
+ end
16
+
17
+ private
18
+
19
+ def calculate_check_digit(partial_vin)
20
+ values = mapped_vin_values(partial_vin)
21
+ values = weighted_values(values)
22
+ check_digit_value(sum_of_products(values))
23
+ end
24
+
25
+ def check_digit_value(total)
26
+ return 'X' if total % 11 == 10
27
+ total % 11
28
+ end
29
+
30
+ def serial
31
+ (sprintf '%06d', SecureRandom.random_number(999999)).split(//)
32
+ end
33
+
34
+ def mapped_vin_values(partial_vin)
35
+ partial_vin.map { |v| Vinbot::Data::Constants::EBCDIC_MAP[v].nil? ? v.to_i : Vinbot::Data::Constants::EBCDIC_MAP[v].to_i }
36
+ end
37
+
38
+ def weighted_values(values)
39
+ (0...values.count).inject([]) { |r, i| r << values[i] * Vinbot::Data::Constants::WEIGHT_FACTORS[i] }
40
+ end
41
+
42
+ def sum_of_products(products)
43
+ products.inject(:+)
44
+ end
45
+ end
46
+
47
+ end
48
+ end
data/lib/vinbot.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'securerandom'
2
+ require 'sequel'
3
+ require 'sqlite3'
4
+ require 'vin_bank'
5
+ require 'vinbot/vehicle'
6
+ require 'vinbot/vin'
7
+
8
+ DB = Sequel.sqlite(VinBank.db_path)
9
+ Dir["#{File.dirname(__FILE__)}/data/*.rb"].each {|file| require file }
10
+
11
+ module Vinbot
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vinbot
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jarod Adair, Umair Chagani
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-nav
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sequel
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: vin_bank
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 3.0.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 3.0.0
125
+ description: Vinbot generates decodeable vins and provides a vehicle object that includes
126
+ real vehicle data.
127
+ email:
128
+ - jarod.adair@manheim.com, umair.chagani@manheim.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - lib/data/body_type.rb
134
+ - lib/data/constants.rb
135
+ - lib/data/drivetrain.rb
136
+ - lib/data/engine_type.rb
137
+ - lib/data/exterior_color.rb
138
+ - lib/data/interior_color.rb
139
+ - lib/data/make.rb
140
+ - lib/data/model.rb
141
+ - lib/data/transmission.rb
142
+ - lib/data/trim.rb
143
+ - lib/data/vehicle.rb
144
+ - lib/data/vehicle_type.rb
145
+ - lib/data/year.rb
146
+ - lib/vinbot.rb
147
+ - lib/vinbot/vehicle.rb
148
+ - lib/vinbot/version.rb
149
+ - lib/vinbot/vin.rb
150
+ homepage: https://github.com/manheim/vinbot
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.2.2
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Vinbot generates decodeable vins and provides a vehicle object that includes
174
+ real vehicle data.
175
+ test_files: []