# File lib/openurl/context_object.rb, line 255
    def import_hash(hash)            
      ref = {}
      openurl_keys = ["url_ver", "url_tim", "url_ctx_fmt"]
      hash.each do |key, value|        
        val = value
        val = value[0] if value.is_a?(Array)
        if openurl_keys.include?(key)          
          next # None of these matter much for our purposes
        elsif @admin.has_key?(key)          
          self.set_administration_key(key, val)          
        elsif key.downcase.match(/^[a-z]{3}_val_fmt$/)          
          (entity, v, fmt) = key.split("_")
          ent = self.translate_abbr(entity)           
          eval("@"+ent).set_format(val)
        elsif key.match(/^[a-z]{3}_ref/)
          # determines if we have a by-reference context object
          (entity, v, fmt) = key.split("_")
          ent = self.translate_abbr(entity)
          # by-reference requires two fields, format and location, if this is
          # the first field we've run across, set a place holder until we get
          # the other value          
          unless ref[entity]
            if fmt
              ref_key = "format"
            else 
              ref_key = "location"
            end
            ref[entity] = [ref_key, val]
          else
            if ref[entity][0] == "format"
              eval("@"+ent).set_reference(val, ref[entity][1])
            else
              eval("@"+ent).set_reference(ref[entity][1], val)
            end
          end
        elsif key.match(/^[a-z]{3}_id$/)
          # Get the entity identifier
          (entity, v) = key.split("_")
          ent = self.translate_abbr(entity)
          if value.is_a?(Array)
            value.each do | id |
              eval("@"+ent).add_identifier(id)
            end
          else
            eval("@"+ent).add_identifier(val)      
          end          
        elsif key.match(/^[a-z]{3}_dat$/)
          # Get any private data          
          (entity, v) = key.split("_")
          ent = self.translate_abbr(entity)
          eval("@"+ent).set_private_data(val)  
        else
          # collect the entity metadata
          keyparts = key.split(".")            
          if keyparts.length > 1
            # This is 1.0 OpenURL
            ent = self.translate_abbr(keyparts[0])
            eval("@"+ent).set_metadata(keyparts[1], val)
          else
            # This is a 0.1 OpenURL.  Your mileage may vary on how accurately
            # this maps.
            if key == 'id'
              if value.is_a?(Array)
                value.each do | id |
                  @referent.add_identifier(id)
                end
              else
                @referent.add_identifier(val)
              end              
            elsif key == 'sid'
              @referrer.set_identifier("info:sid/"+val.to_s)            
            else 
              @referent.set_metadata(key, val)
            end
          end
        end
      end  
      
      # Initialize a new ContextObject object from an existing key/value hash
      
      def self.new_from_hash(hash)
        co = self.new
        co.import_hash(hash)
        return co
      end
      
      # if we don't have a referent format (most likely because we have a 0.1
      # OpenURL), try to determine something from the genre.  If that doesn't 
      # exist, just call it a journal since most 0.1 OpenURLs would be one,
      # anyway.
      unless @referent.format        
       fmt = case @referent.metadata['genre']
         when /article|journal|issue|proceeding|conference|preprint/ then 'journal'
         when /book|bookitem|report|document/ then 'book'
         else 'journal'
         end
       @referent.set_format(fmt)
      end
    end