File: sort.rb

package info (click to toggle)
ruby-http-accept 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 136 kB
  • sloc: ruby: 352; makefile: 4
file content (16 lines) | stat: -rw-r--r-- 444 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2016-2024, by Samuel Williams.

module HTTP
	module Accept
		module Sort
			# This sorts items with higher priority first, and keeps items with the same priority in the same relative order.
			def self.by_quality_factor(items)
				# We do this to get a stable sort:
				items.sort_by.with_index{|object, index| [-object.quality_factor, index]}
			end
		end
	end
end