Method: Sprockets::HTTPUtils#find_q_matches
- Defined in:
- lib/sprockets/http_utils.rb
#find_q_matches(q_values, available, &matcher) ⇒ Object
Internal: Find all qvalue matches from an Array of available options.
Adapted from Rack::Utils#q_values.
Returns Array of matched Strings from available Array or [].
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/sprockets/http_utils.rb', line 58 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 |