Sha256: 57bc8cebbf59471713eb8e018cb3e615c941e27b231f4c3f1f462aed159edcf7

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

require 'vin_exploder/abstract_adapter'
require 'vin_exploder/explosion'
require 'vinquery'

module VinExploder
  
  module Decode
    
    class VinqueryAdapter < AbstractAdapter
      
      # Create new vinquery adapter
      #
      # == Parameters
      # options:: access_code, report_type, url
      def initialize(options)
        super
      end
      
      def explode(vin)
        vq = fetch(vin)
        hash = normalize(vq.attributes)
        hash[:errors] = vq.errors
        hash
      end
      
      
      def fetch(vin)
        Vinquery.get(vin, @options)
      end
      
      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
      
    end
    
  end
  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vinquery-0.5.0 lib/vinquery/vin_exploder/adapter.rb
vinquery-0.4.2 lib/vinquery/vin_exploder/adapter.rb
vinquery-0.4.1 lib/vinquery/vin_exploder/adapter.rb
vinquery-0.4.0 lib/vinquery/vin_exploder/adapter.rb
vinquery-0.3.9 lib/vinquery/vin_exploder/adapter.rb
vinquery-0.3.8 lib/vinquery/vin_exploder/adapter.rb
vinquery-0.3.7 lib/vinquery/vin_exploder/adapter.rb
vinquery-0.3.6 lib/vinquery/vin_exploder/adapter.rb