From a8d05ea6252b9cf8991af474e00452b49f825754 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Thu, 13 Oct 2016 04:32:42 +0300 Subject: [PATCH] Expose the most and least number of conflicts --- app/models/conflicts_for_talk.rb | 7 +++++++ app/models/summary.rb | 8 ++++++++ app/views/summaries/show.json.jbuilder | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/conflicts_for_talk.rb b/app/models/conflicts_for_talk.rb index 0b554d7..88e685f 100644 --- a/app/models/conflicts_for_talk.rb +++ b/app/models/conflicts_for_talk.rb @@ -1,2 +1,9 @@ class ConflictsForTalk < ApplicationRecord + def self.most + first + end + + def self.least + last + end end diff --git a/app/models/summary.rb b/app/models/summary.rb index d38bb7d..36b6fe1 100644 --- a/app/models/summary.rb +++ b/app/models/summary.rb @@ -9,6 +9,14 @@ class Summary .uniq.count end + def most_conflicts + ConflictsForTalk.where(talk_id: talk_ids).most.conflicts + end + + def least_conflicts + ConflictsForTalk.where(talk_id: talk_ids).least.conflicts + end + def ranking @ranking ||= Ranking.new(talk_ids: talk_ids).ranking end diff --git a/app/views/summaries/show.json.jbuilder b/app/views/summaries/show.json.jbuilder index 3b996b8..6f5ae26 100644 --- a/app/views/summaries/show.json.jbuilder +++ b/app/views/summaries/show.json.jbuilder @@ -1 +1 @@ -json.extract! @summary, :number_of_ballots, :ranking +json.extract! @summary, :number_of_ballots, :most_conflicts, :least_conflicts, :ranking