Commit f043f5b4e9b50d5e015858e0ab47bffef520bbc9
1 parent
4abe0130
Exists in
master
and in
1 other branch
more whitespace fixes
Showing
1 changed file
with
22 additions
and
22 deletions
Show diff stats
app/models/question.rb
| ... | ... | @@ -85,28 +85,28 @@ class Question < ActiveRecord::Base |
| 85 | 85 | return @p |
| 86 | 86 | end |
| 87 | 87 | |
| 88 | - # adapted from ruby cookbook(2006): section 5-11 | |
| 89 | - def catchup_choose_prompt | |
| 90 | - weighted = catchup_prompts_weights | |
| 91 | - # Rand returns a number from 0 - 1, so weighted needs to be normalized | |
| 92 | - prompt = nil | |
| 93 | - | |
| 94 | - until prompt && prompt.active? | |
| 95 | - target = rand | |
| 96 | - left_choice_id = right_choice_id = nil | |
| 97 | - | |
| 98 | - weighted.each do |item, weight| | |
| 99 | - if target <= weight | |
| 100 | - left_choice_id, right_choice_id = item.split(", ") | |
| 101 | - break | |
| 102 | - end | |
| 103 | - target -= weight | |
| 104 | - end | |
| 105 | - 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 }]) | |
| 106 | - end | |
| 107 | - # check if prompt has two active choices here, maybe we can set this on the prompt level too? | |
| 108 | - prompt | |
| 109 | - end | |
| 88 | + # adapted from ruby cookbook(2006): section 5-11 | |
| 89 | + def catchup_choose_prompt | |
| 90 | + weighted = catchup_prompts_weights | |
| 91 | + # Rand returns a number from 0 - 1, so weighted needs to be normalized | |
| 92 | + prompt = nil | |
| 93 | + | |
| 94 | + until prompt && prompt.active? | |
| 95 | + target = rand | |
| 96 | + left_choice_id = right_choice_id = nil | |
| 97 | + | |
| 98 | + weighted.each do |item, weight| | |
| 99 | + if target <= weight | |
| 100 | + left_choice_id, right_choice_id = item.split(", ") | |
| 101 | + break | |
| 102 | + end | |
| 103 | + target -= weight | |
| 104 | + end | |
| 105 | + 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 }]) | |
| 106 | + end | |
| 107 | + # check if prompt has two active choices here, maybe we can set this on the prompt level too? | |
| 108 | + prompt | |
| 109 | + end | |
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | def catchup_prompts_weights | ... | ... |