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
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
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 [].