Class: Equalshares::TieBreaker::Lexico
- Inherits:
-
Object
- Object
- Equalshares::TieBreaker::Lexico
- Defined in:
- lib/equalshares/tie_breaker.rb
Overview
A total order (pabutools-style): rank tied projects by their position in the list and keep the first.
Instance Method Summary collapse
- #filter(remaining, _ctx) ⇒ Object
-
#initialize(order) ⇒ Lexico
constructor
A new instance of Lexico.
- #sort_key(project_id, _ctx) ⇒ Object
Constructor Details
#initialize(order) ⇒ Lexico
Returns a new instance of Lexico.
62 63 64 65 |
# File 'lib/equalshares/tie_breaker.rb', line 62 def initialize(order) @order = order @position = order.each_with_index.to_h end |
Instance Method Details
#filter(remaining, _ctx) ⇒ Object
67 68 69 |
# File 'lib/equalshares/tie_breaker.rb', line 67 def filter(remaining, _ctx) [remaining.min_by { |c| @position[c] || @order.length }] end |
#sort_key(project_id, _ctx) ⇒ Object
71 72 73 |
# File 'lib/equalshares/tie_breaker.rb', line 71 def sort_key(project_id, _ctx) @position[project_id] || @order.length end |