Class: VinExploder::Exploder

Inherits:
Object
  • Object
show all
Defined in:
lib/vin_exploder/exploder.rb

Instance Method Summary collapse

Constructor Details

#initialize(adapter, cache = nil) ⇒ Exploder

Returns a new instance of Exploder.

Raises:



8
9
10
11
12
# File 'lib/vin_exploder/exploder.rb', line 8

def initialize(adapter, cache=nil)
  raise MissingAdapter.new("No vin decoding vendor adapter has been provided.") if adapter.nil?
  @cache = cache ? cache : Cache::Store.new
  @adapter = adapter
end

Instance Method Details

#get(vin) ⇒ Object

Get vin Explosion.

Parameters

vin

vehicle identification number

Return

An Explosion object containing the decoded vin attributes



21
22
23
24
25
26
27
28
# File 'lib/vin_exploder/exploder.rb', line 21

def get(vin)
  hash = @cache.fetch(vin) do
    @adapter.explode(vin)
  end
  errors = hash ? hash.delete(:errors) : []
  data = hash ? hash : {}
  Explosion.new vin, data, errors
end