Class: Equalshares::TieBreaker::ExplicitList
- Inherits:
-
Object
- Object
- Equalshares::TieBreaker::ExplicitList
- Defined in:
- lib/equalshares/tie_breaker.rb
Overview
JS-faithful explicit list: keep the first choice that appears anywhere in the list (does NOT respect the list's ordering). Kept for bit-compatibility with the equalshares.net tool; prefer Lexico for an order-respecting tie-break.
Instance Method Summary collapse
- #filter(remaining, _ctx) ⇒ Object
-
#initialize(list) ⇒ ExplicitList
constructor
A new instance of ExplicitList.
- #sort_key(project_id, _ctx) ⇒ Object
Constructor Details
#initialize(list) ⇒ ExplicitList
Returns a new instance of ExplicitList.
80 81 82 83 |
# File 'lib/equalshares/tie_breaker.rb', line 80 def initialize(list) @list = list @position = list.each_with_index.to_h end |
Instance Method Details
#filter(remaining, _ctx) ⇒ Object
85 86 87 88 |
# File 'lib/equalshares/tie_breaker.rb', line 85 def filter(remaining, _ctx) found = remaining.find { |c| @list.include?(c) } found ? [found] : remaining end |
#sort_key(project_id, _ctx) ⇒ Object
90 91 92 |
# File 'lib/equalshares/tie_breaker.rb', line 90 def sort_key(project_id, _ctx) @position[project_id] || @list.length end |