Module Algorithms::Prompt
In: lib/algorithms/prompt.rb

Methods

Public Instance methods

Test if prompt is bad. Prompt is bad if it does not have 2 items or if any of its items are nil.

[Source]

    # File lib/algorithms/prompt.rb, line 35
35:   def bad_prompt?(prompt)
36:     return (prompt.items.length != 2 || prompt.items.any?(&:nil?))
37:   end

[Source]

    # File lib/algorithms/prompt.rb, line 39
39:   def conditions(question_id)
40:     {
41:       :joins => "INNER JOIN items_questions ON (items_questions.question_id=#{question_id} AND items_questions.item_id=items.id)",
42:       :conditions => { :active => true },
43:     }
44:   end

Generate count number of prompts based on question and voter. Choose generation algorithm based on prime.

Return

An array of prompts

Parameters

question_id<int>:Prompts for this question ID.
voter_id<int>:Prompts for this voter ID.
count<int>:This number of prompts.
prompt<bool>:If true primed prompts are generated, otherwise random

prompts are generated.

[Source]

    # File lib/algorithms/prompt.rb, line 12
12:   def create_prompts(question_id, voter_id, count, algo)
13:     srand if PRODUCTION
14:     case algo
15:     when 2
16:       prompts = Algorithms::Prompt::Popular.prompts(question_id, voter_id, count)
17:     when 3
18:       prompts = Algorithms::Prompt::Extremes.prompts(question_id, voter_id, count)
19:     end
20:     prompts || Algorithms::Prompt::Random.prompts(question_id, voter_id, count)
21:   end

Create default prompt

[Source]

    # File lib/algorithms/prompt.rb, line 24
24:   def prompt_for_request(question_id, voter_id, algorithm_id)
25:     Prompt.create(
26:       :question_id => question_id,
27:       :voter_id => voter_id,
28:       :prompt_algorithm_id => algorithm_id,
29:       :active => false
30:     )
31:   end

[Validate]