From f043f5b4e9b50d5e015858e0ab47bffef520bbc9 Mon Sep 17 00:00:00 2001 From: Luke Baker Date: Wed, 8 Dec 2010 11:15:07 -0500 Subject: [PATCH] more whitespace fixes --- app/models/question.rb | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/app/models/question.rb b/app/models/question.rb index c64666a..8a964d6 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -85,28 +85,28 @@ class Question < ActiveRecord::Base return @p end - # adapted from ruby cookbook(2006): section 5-11 - def catchup_choose_prompt - weighted = catchup_prompts_weights - # Rand returns a number from 0 - 1, so weighted needs to be normalized - prompt = nil - - until prompt && prompt.active? - target = rand - left_choice_id = right_choice_id = nil - - weighted.each do |item, weight| - if target <= weight - left_choice_id, right_choice_id = item.split(", ") - break - end - target -= weight - end - prompt = prompts.find_or_create_by_left_choice_id_and_right_choice_id(left_choice_id, right_choice_id, :include => [{ :left_choice => :item }, { :right_choice => :item }]) - end - # check if prompt has two active choices here, maybe we can set this on the prompt level too? - prompt - end + # adapted from ruby cookbook(2006): section 5-11 + def catchup_choose_prompt + weighted = catchup_prompts_weights + # Rand returns a number from 0 - 1, so weighted needs to be normalized + prompt = nil + + until prompt && prompt.active? + target = rand + left_choice_id = right_choice_id = nil + + weighted.each do |item, weight| + if target <= weight + left_choice_id, right_choice_id = item.split(", ") + break + end + target -= weight + end + prompt = prompts.find_or_create_by_left_choice_id_and_right_choice_id(left_choice_id, right_choice_id, :include => [{ :left_choice => :item }, { :right_choice => :item }]) + end + # check if prompt has two active choices here, maybe we can set this on the prompt level too? + prompt + end def catchup_prompts_weights -- libgit2 0.21.2