module Sprockets::HTTPUtils
def find_q_matches(q_values, available, &matcher)
Adapted from Rack::Utils#q_values.
Internal: Find all qvalue matches from an Array of available options.
def find_q_matches(q_values, available, &matcher) matcher ||= lambda { |a, b| a == b } matches = [] case q_values when Array when String q_values = parse_q_values(q_values) when NilClass q_values = [] else raise TypeError, "unknown q_values type: #{q_values.class}" end q_values.each do |accepted, quality| if match = available.find { |option| matcher.call(option, accepted) } matches << [match, quality] end end matches.sort_by! { |match, quality| -quality } matches.map! { |match, quality| match } matches end