vin_exploder 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/vin_exploder/cache/couchrest_cache_store.rb +2 -3
- data/lib/vin_exploder/cache.rb +10 -5
- data/lib/vin_exploder/configuration.rb +2 -2
- data/lib/vin_exploder/exploder.rb +3 -2
- data/lib/vin_exploder/explosion.rb +3 -2
- data/lib/vin_exploder/version.rb +1 -1
- data/lib/vin_exploder.rb +1 -0
- data/spec/cache/activerecord_cache_store_spec.rb +1 -1
- data/spec/cache/cache_store_spec.rb +4 -3
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -19,9 +19,8 @@ module Cache
|
|
19
19
|
def read(vin)
|
20
20
|
key = make_vin_cache_key(vin)
|
21
21
|
result = @db.get(key)['data'] rescue nil
|
22
|
-
hash =
|
23
|
-
|
24
|
-
hash.empty? ? nil : hash
|
22
|
+
hash = symbolize_result_hash(result) unless result.nil?
|
23
|
+
hash
|
25
24
|
end
|
26
25
|
|
27
26
|
def write(vin, hash)
|
data/lib/vin_exploder/cache.rb
CHANGED
@@ -33,15 +33,14 @@ module VinExploder
|
|
33
33
|
# cache.fetch("VIN_NUMBER_2") # => {:make => 'Dodge', :model => '1500'}
|
34
34
|
#
|
35
35
|
def fetch(vin)
|
36
|
+
hash = read(vin)
|
36
37
|
if block_given?
|
37
|
-
hash = read(vin)
|
38
38
|
if hash.nil?
|
39
39
|
hash = yield
|
40
|
-
write(vin, hash)
|
40
|
+
write(vin, hash) unless hash.empty? || (hash[:errors] && !hash[:errors].empty?)
|
41
41
|
end
|
42
|
-
else
|
43
|
-
hash = read(vin)
|
44
42
|
end
|
43
|
+
hash
|
45
44
|
end
|
46
45
|
|
47
46
|
# Fetches VIN data from the cache, using the given key. If VIN has
|
@@ -67,7 +66,13 @@ module VinExploder
|
|
67
66
|
# Position 9 is a checksum value and should not be used in the key.
|
68
67
|
def make_vin_cache_key(vin)
|
69
68
|
key = vin.slice(0,8)
|
70
|
-
key << vin.slice(
|
69
|
+
key << vin.slice(9,2)
|
70
|
+
end
|
71
|
+
|
72
|
+
def symbolize_result_hash(hash)
|
73
|
+
new_hash = {}
|
74
|
+
hash.each{|k,v| new_hash[k.to_sym] = v}
|
75
|
+
new_hash
|
71
76
|
end
|
72
77
|
|
73
78
|
end
|
@@ -16,7 +16,7 @@ module VinExploder
|
|
16
16
|
if args.empty?
|
17
17
|
case @cache_store
|
18
18
|
when Symbol
|
19
|
-
VinExploder::Cache.const_get(@cache_store.to_s.split('_').map{|s| s.capitalize }.join)
|
19
|
+
@cache_store = VinExploder::Cache.const_get(@cache_store.to_s.split('_').map{|s| s.capitalize }.join)
|
20
20
|
else
|
21
21
|
@cache_store
|
22
22
|
end
|
@@ -30,7 +30,7 @@ module VinExploder
|
|
30
30
|
if args.empty?
|
31
31
|
case @adapter
|
32
32
|
when Symbol
|
33
|
-
VinExploder::Decode.const_get(@adapter.to_s.split('_').map{|s| s.capitalize }.join)
|
33
|
+
@adapter = VinExploder::Decode.const_get(@adapter.to_s.split('_').map{|s| s.capitalize }.join)
|
34
34
|
else
|
35
35
|
@adapter
|
36
36
|
end
|
@@ -20,10 +20,11 @@ module VinExploder
|
|
20
20
|
# An Explosion object containing the decoded vin attributes
|
21
21
|
def get(vin)
|
22
22
|
hash = @cache.fetch(vin) do
|
23
|
-
# get from vender adapter
|
24
23
|
@adapter.explode(vin)
|
25
24
|
end
|
26
|
-
|
25
|
+
errors = hash ? hash.delete(:errors) : []
|
26
|
+
data = hash ? hash : {}
|
27
|
+
Explosion.new vin, data, errors
|
27
28
|
end
|
28
29
|
|
29
30
|
end
|
@@ -4,7 +4,7 @@ module VinExploder
|
|
4
4
|
|
5
5
|
class Explosion
|
6
6
|
|
7
|
-
attr_reader :vin, :success, :errors, :make, :model, :year, :driveline, :body_style, :fuel_type, :all
|
7
|
+
attr_reader :vin, :success, :errors, :make, :model, :year, :driveline, :body_style, :fuel_type, :number_of_doors, :all
|
8
8
|
|
9
9
|
def initialize(vin, vin_hash, errors={})
|
10
10
|
@vin = vin
|
@@ -15,8 +15,9 @@ module VinExploder
|
|
15
15
|
@driveline = @all[:driveline]
|
16
16
|
@body_style = @all[:body_style]
|
17
17
|
@fuel_type = @all[:fuel_type]
|
18
|
+
@number_of_doors = @all[:number_of_doors]
|
18
19
|
@trim_level = @all[:trim_level]
|
19
|
-
@errors = errors.nil? ?
|
20
|
+
@errors = errors.nil? ? [] : errors
|
20
21
|
@success = @errors.empty?
|
21
22
|
end
|
22
23
|
|
data/lib/vin_exploder/version.rb
CHANGED
data/lib/vin_exploder.rb
CHANGED
@@ -23,11 +23,12 @@ describe Store do
|
|
23
23
|
|
24
24
|
describe '#fetch' do
|
25
25
|
it 'should execute the block and pass through #write' do
|
26
|
+
result = {'vin' => 'EXPLODED_VIN'}
|
26
27
|
store = Store.new
|
27
|
-
store.
|
28
|
+
store.should_not_receive(:write).exactly(1).times
|
28
29
|
store.fetch('VIN') do
|
29
|
-
|
30
|
-
end.should ==
|
30
|
+
result
|
31
|
+
end.should == result
|
31
32
|
end
|
32
33
|
|
33
34
|
it 'should return nil with no block' do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: vin_exploder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.4.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jake Mallory
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-28 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|