lib/vin_exploder/cache.rb in vin_exploder-0.3.1 vs lib/vin_exploder/cache.rb in vin_exploder-0.4.0

- old
+ new

@@ -31,19 +31,18 @@ # {:make => 'Dodge', :model => '1500'} # end # cache.fetch("VIN_NUMBER_2") # => {:make => 'Dodge', :model => '1500'} # def fetch(vin) + hash = read(vin) if block_given? - hash = read(vin) if hash.nil? hash = yield - write(vin, hash) + write(vin, hash) unless hash.empty? || (hash[:errors] && !hash[:errors].empty?) end - else - hash = read(vin) end + hash end # Fetches VIN data from the cache, using the given key. If VIN has # been cached with the given key, then the VIN attributes are returned. Otherwise, # nil is returned. @@ -65,10 +64,16 @@ # the cache key for vins should be based on characters 0-8, 10-11. # Position 9 is a checksum value and should not be used in the key. def make_vin_cache_key(vin) key = vin.slice(0,8) - key << vin.slice(10,2) + key << vin.slice(9,2) + end + + def symbolize_result_hash(hash) + new_hash = {} + hash.each{|k,v| new_hash[k.to_sym] = v} + new_hash end end end \ No newline at end of file