vinbot 2.0.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/data/body_type.rb +7 -0
- data/lib/data/constants.rb +12 -0
- data/lib/data/drivetrain.rb +7 -0
- data/lib/data/engine_type.rb +7 -0
- data/lib/data/exterior_color.rb +7 -0
- data/lib/data/interior_color.rb +7 -0
- data/lib/data/make.rb +7 -0
- data/lib/data/model.rb +7 -0
- data/lib/data/transmission.rb +7 -0
- data/lib/data/trim.rb +7 -0
- data/lib/data/vehicle.rb +35 -0
- data/lib/data/vehicle_type.rb +7 -0
- data/lib/data/year.rb +7 -0
- data/lib/vinbot.rb +19 -0
- data/lib/vinbot/vehicle.rb +24 -0
- data/lib/vinbot/version.rb +3 -0
- data/lib/vinbot/vin.rb +48 -0
- metadata +173 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 157017b7abf7d9b47060edb0abecaf362e1bfb32
|
4
|
+
data.tar.gz: fbddeaaa55b5db5174e99450dc5dd7aaa28cabf9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d6840c589dbf315e0da3ae86d50fc36f125cb4ceff601af8fb54dbf5723b9ec26f7f373a49053075150feb079700c8436c41637ff6fbb74ba62a58cbce4c4dd
|
7
|
+
data.tar.gz: d1d584ad506f6dcb5b4870a617b973f30d55cc882950f44c04df3e5f817169d7e308d76bd29858756ddcaae51de4106ff72e62846012e5ba14e93f26a0105c7a
|
@@ -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
|
data/lib/data/make.rb
ADDED
data/lib/data/model.rb
ADDED
data/lib/data/trim.rb
ADDED
data/lib/data/vehicle.rb
ADDED
@@ -0,0 +1,35 @@
|
|
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
|
+
|
16
|
+
def self.get_vehicle(params)
|
17
|
+
return get_random_vehicle if params.empty?
|
18
|
+
join_query = perform_joins(params)
|
19
|
+
add_conditions_to_join(join_query, params).order(Sequel.lit('RANDOM()')).limit(1).first
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.perform_joins(params)
|
23
|
+
params.keys.inject(from(:vehicles)) { |r, e| r.join("#{e}s".to_sym, :id => "vehicles__#{e}_id".to_sym) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.add_conditions_to_join(join_query, params)
|
27
|
+
params.inject(join_query) { |r, e| r.where("#{e.first}s__name".to_sym => e.last) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_random_vehicle
|
31
|
+
::Vinbot::Data::Vehicle.order(Sequel.lit('RANDOM()')).limit(1).first
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/data/year.rb
ADDED
data/lib/vinbot.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'sequel'
|
3
|
+
require 'vin_bank'
|
4
|
+
require 'vinbot/vehicle'
|
5
|
+
require 'vinbot/vin'
|
6
|
+
|
7
|
+
if RUBY_PLATFORM == 'java'
|
8
|
+
require 'jdbc/sqlite3'
|
9
|
+
DB = Sequel.connect("jdbc:sqlite:///#{VinBank.db_path}")
|
10
|
+
else
|
11
|
+
require 'sqlite3'
|
12
|
+
DB = Sequel.sqlite(VinBank.db_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
Dir["#{File.dirname(__FILE__)}/data/*.rb"].each { |file| require file }
|
16
|
+
|
17
|
+
module Vinbot
|
18
|
+
|
19
|
+
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(params = {})
|
8
|
+
vehicle = ::Vinbot::Data::Vehicle.get_vehicle(params)
|
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
|
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
|
metadata
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vinbot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.2
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Jarod Adair, Umair Chagani
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>'
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - '>'
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '1.8'
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '10.0'
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
prerelease: false
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
prerelease: false
|
68
|
+
type: :development
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-nav
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
prerelease: false
|
82
|
+
type: :development
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: jdbc-sqlite3
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
prerelease: false
|
96
|
+
type: :runtime
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sequel
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
prerelease: false
|
110
|
+
type: :runtime
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: vin_bank
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 3.1.0
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 3.1.0
|
123
|
+
prerelease: false
|
124
|
+
type: :runtime
|
125
|
+
description: Vinbot generates decodeable vins and provides a vehicle object that includes real vehicle data.
|
126
|
+
email:
|
127
|
+
- jarod.adair@manheim.com, umair.chagani@manheim.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- lib/vinbot.rb
|
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/vehicle.rb
|
147
|
+
- lib/vinbot/version.rb
|
148
|
+
- lib/vinbot/vin.rb
|
149
|
+
homepage: https://github.com/manheim/vinbot
|
150
|
+
licenses:
|
151
|
+
- MIT
|
152
|
+
metadata: {}
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 2.1.9
|
170
|
+
signing_key:
|
171
|
+
specification_version: 4
|
172
|
+
summary: Vinbot generates decodeable vins and provides a vehicle object that includes real vehicle data.
|
173
|
+
test_files: []
|