Class: CategoryTextKeyGenerator

Inherits:
Object
  • Object
show all
Includes:
GenerateAnswerKey
Defined in:
lib/category_text_key_generator.rb

Overview

Generate a key with location of the correct answer based length of the category text

Class Method Summary collapse

Methods included from GenerateAnswerKey

get_random_key, get_random_phrase, get_random_word

Class Method Details

.decrypt_answer_key(question) ⇒ integer

Decrypt answer key

Parameters:

  • question (hash)

Returns:

  • (integer)

    index of the correct answer from the answer array



34
35
36
37
# File 'lib/category_text_key_generator.rb', line 34

def self.decrypt_answer_key(question)
	location = question[:category].length % 10
	question[:answer_key][location].to_i
end

.update_answer_key(question) ⇒ hash

Encrypt answer_key

Parameters:

  • question (hash)

    question information

Returns:

  • (hash)

    answer key



18
19
20
21
22
23
24
25
# File 'lib/category_text_key_generator.rb', line 18

def self.update_answer_key(question)
	correct_answer = question[:answer_key].to_s
	location = question[:category].length % 10
	answer_key = GenerateAnswerKey.get_random_key(location) +
                    correct_answer +
                    GenerateAnswerKey.get_random_key(9 - location)
	question[:answer_key] = answer_key
end