From 63a920a88b949e4521ec321288edbf8073b3de39 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Wed, 5 Oct 2016 13:28:56 +0300 Subject: [PATCH] Add a conflict coefficient representation as a hash --- app/models/conflict_coefficient.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/models/conflict_coefficient.rb b/app/models/conflict_coefficient.rb index 8228e84..9ad0f66 100644 --- a/app/models/conflict_coefficient.rb +++ b/app/models/conflict_coefficient.rb @@ -7,6 +7,17 @@ class ConflictCoefficient end end + def self.all_as_hash + conflicts_hash = {} + + all.each do |coefficient| + conflicts_hash[coefficient.left] = {} unless conflicts_hash[coefficient.left] + conflicts_hash[coefficient.left][coefficient.right] = coefficient.per_cent + end + + conflicts_hash + end + def conflicts @conflicts ||= talk_preferences.select do |talk_preference| talk_preference.include_all? [@left, @right]