def fitness_and_quality_parsed(mime_type, parsed_ranges)
    best_fitness = -1
    best_fit_q = 0
    target_type, target_subtype, target_params = parse_media_range(mime_type)

    parsed_ranges.each do |type,subtype,params|
      if (type == target_type or type == "*" or target_type == "*") and
          (subtype == target_subtype or subtype == "*" or target_subtype == "*")
        param_matches = target_params.find_all { |k,v| k != "q" and params.has_key?(k) and v == params[k] }.length

        fitness = (type == target_type) ? 100 : 0
        fitness += (subtype == target_subtype) ? 10 : 0
        fitness += param_matches

        if fitness > best_fitness
          best_fitness = fitness
          best_fit_q = params["q"]
        end
      end
    end

    [best_fitness, best_fit_q.to_f]
  end
def fitness_and_quality_parsed(mime_type, parsed_ranges)
    best_fitness = -1
    best_fit_q = 0
    target_type, target_subtype, target_params = parse_media_range(mime_type)

    parsed_ranges.each do |type,subtype,params|
      if (type == target_type or type == "*" or target_type == "*") and
          (subtype == target_subtype or subtype == "*" or target_subtype == "*")
        param_matches = target_params.find_all { |k,v| k != "q" and params.has_key?(k) and v == params[k] }.length

        fitness = (type == target_type) ? 100 : 0
        fitness += (subtype == target_subtype) ? 10 : 0
        fitness += param_matches

        if fitness > best_fitness
          best_fitness = fitness
          best_fit_q = params["q"]
        end
      end
    end

    [best_fitness, best_fit_q.to_f]
  end
Find the best match for a given mime-type against a list of
  media_ranges that have already been parsed by #parse_media_range

 Returns the fitness and the "q" quality parameter of the best match,
  or [-1, 0] if no match was found. Just as for #quality_parsed,
  "parsed_ranges" must be an Enumerable of parsed media ranges.