From 52d31ea0cac5961a920111e3ce4274a303f7599c Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Sat, 28 Oct 2017 16:07:48 -0400 Subject: [PATCH] reversed options as well --- app/models/question.rb | 7 ++++++- app/views/shared/_histogram.html.haml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/question.rb b/app/models/question.rb index 13d83108..4b39ea38 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -32,8 +32,13 @@ class Question < ApplicationRecord [option1, option2, option3, option4, option5] end + def options_with_reverse + return options.reverse if reverse? + options + end + def option_index(answer) - options.map(&:downcase).map(&:strip).index(answer.downcase.strip) + options_with_reverse.map(&:downcase).map(&:strip).index(answer.downcase.strip) end def aggregated_responses_for_school(school) diff --git a/app/views/shared/_histogram.html.haml b/app/views/shared/_histogram.html.haml index 2fe088ab..0f745f35 100644 --- a/app/views/shared/_histogram.html.haml +++ b/app/views/shared/_histogram.html.haml @@ -1,7 +1,7 @@ - histogram = data.responses.map(&:answer_index_with_reverse).group_by { |a| a.to_s } %table.answers %tbody - - data.question.options.each_with_index do |option, index| + - data.question.options_with_reverse.each_with_index do |option, index| %tr.answer - group = histogram[(index + 1).to_s] - width = (100 * (group.blank? ? 0 : group.length)) / histogram.values.flatten.length