Module: Equalshares::TieBreaker
- Defined in:
- lib/equalshares/tie_breaker.rb
Overview
Tie-breaking strategies. Each element of params.tie_breaking maps to one strategy object (via TieBreaker.for). A strategy can either narrow a tied set (#filter, used to resolve a single tie in priority order) or contribute a sort key (#sort_key, used to build a total order over all projects). Mirrors pabutools' TieBreakingRule.
Defined Under Namespace
Classes: Context, ExplicitList, Extreme, Lexico, MaxCost, MaxVotes, MinCost
Class Method Summary collapse
Class Method Details
.for(method) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/equalshares/tie_breaker.rb', line 14 def for(method) case method when "maxVotes" then MaxVotes.new when "minCost" then MinCost.new when "maxCost" then MaxCost.new when Hash then Lexico.new(lexico_order(method)) when Array then ExplicitList.new(method) else raise ComputeError, "Unknown tie-breaking method: #{method}" end end |
.lexico_order(method) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/equalshares/tie_breaker.rb', line 26 def lexico_order(method) order = method[:lexico] || method["lexico"] raise ComputeError, "Unknown tie-breaking method: #{method}" unless order.is_a?(Array) order end |