Class: VinExploder::Decode::VinqueryAdapter

Inherits:
AbstractAdapter
  • Object
show all
Defined in:
lib/vinquery/vin_exploder/adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ VinqueryAdapter

Create new vinquery adapter

Parameters

options

access_code, report_type, url



15
16
17
# File 'lib/vinquery/vin_exploder/adapter.rb', line 15

def initialize(options)
  super
end

Instance Method Details

#explode(vin) ⇒ Object



19
20
21
22
23
24
# File 'lib/vinquery/vin_exploder/adapter.rb', line 19

def explode(vin)
  vq = fetch(vin)
  hash = normalize(vq.attributes)
  hash[:errors] = vq.errors
  hash
end

#fetch(vin) ⇒ Object



27
28
29
# File 'lib/vinquery/vin_exploder/adapter.rb', line 27

def fetch(vin)
  Vinquery.get(vin, @options)
end

#normalize(vq_hash) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vinquery/vin_exploder/adapter.rb', line 31

def normalize(vq_hash)
  # fuel_type = vq_hash[:engine_type].match(/(GAS|DIESEL|HYBRID)/)[0]
  # driveline_type = vq_hash[:driveline].match(/(FWD|4WD|2WD)/)[0]
  unless vq_hash.empty?
    doors_match = vq_hash[:body_style].match(/(\d)-DR/)
    doors_match = (vq_hash[:body_style].match(/VAN/).nil? ? [0,0] : [5,5]) if doors_match.nil?
    vq_hash[:number_of_doors] = doors_match[1]
    vq_hash[:year] = vq_hash.delete(:model_year)
  end
  vq_hash
end