def parse(header)
      qvalues = {}

      header.to_s.split(',').each do |part|
        m = /^\s*([^\s,]+?)(?:\s*;\s*q\s*=\s*(\d+(?:\.\d+)?))?$/.match(part)

        if m
          qvalues[m[1].downcase] = normalize_qvalue((m[2] || 1).to_f)
        else
          raise InvalidHeader, "Invalid header value: #{part.inspect}"
        end
      end

      qvalues
    end
def parse(header)
      qvalues = {}

      header.to_s.split(',').each do |part|
        m = /^\s*([^\s,]+?)(?:\s*;\s*q\s*=\s*(\d+(?:\.\d+)?))?$/.match(part)

        if m
          qvalues[m[1].downcase] = normalize_qvalue((m[2] || 1).to_f)
        else
          raise InvalidHeader, "Invalid header value: #{part.inspect}"
        end
      end

      qvalues
    end
Parses the value of an Accept-style request header into a hash of
 acceptable values and their respective quality factors (qvalues). The
 +join+ method may be used on the resulting hash to obtain a header
 string that is the semantic equivalent of the one provided.