class Test
Basic Test
Class
Constants
- QUESTIONS
The test's questions plus the type of question they are
Public Class Methods
new()
click to toggle source
# File lib/jungi/classes.rb, line 97 def initialize @answers = [] end
Public Instance Methods
answer(*args)
click to toggle source
Alias set_answer
# File lib/jungi/classes.rb, line 146 def answer(*args) set_answer(*args) end
answer=(args)
click to toggle source
Alias set_answer
# File lib/jungi/classes.rb, line 151 def answer=(args) set_answer(*args) end
answers()
click to toggle source
Get a list of the answers so far
# File lib/jungi/classes.rb, line 156 def answers Marshal.load(Marshal.dump(@answers)) end
done?()
click to toggle source
Alias finished?
# File lib/jungi/classes.rb, line 170 def done? self.finished? end
finished?()
click to toggle source
Done supplying answers to questions?
# File lib/jungi/classes.rb, line 161 def finished? if @answers.length >= self.class.const_get(:QUESTIONS).length return true else return false end end
get_question(index)
click to toggle source
Get question via index
# File lib/jungi/classes.rb, line 124 def get_question(index) self.out_of_index? index self.class.const_get(:QUESTIONS)[index].dup end
method_missing(name, *args)
click to toggle source
Enable the use of self.Q<number> for easy implementation of tests
Calls superclass method
# File lib/jungi/classes.rb, line 102 def method_missing(name, *args) section = name[1..(name.length - 1)] if name[0] == 'Q' && self.out_of_index?(section.to_i - 1) return @answers[section.to_i - 1] else super end end
out_of_index?(index, truism = false)
click to toggle source
Check for out of index
# File lib/jungi/classes.rb, line 112 def out_of_index?(index, truism = false) if (index) > (self.class.const_get(:QUESTIONS).length - 1) if truism false else fail "##{index} Out of Index" end end true end
question(*args)
click to toggle source
Alias get_question
# File lib/jungi/classes.rb, line 130 def question(*args) get_question(*args) end
result()
click to toggle source
Stub method for result of test
# File lib/jungi/classes.rb, line 175 def result fail 'Not ready yet!' unless self.finished? @answers.to_s end
set_answer(index, value)
click to toggle source
Set question answer to value
# File lib/jungi/classes.rb, line 135 def set_answer(index, value) self.out_of_index? index type = self.class.const_get(:QUESTIONS)[index][1] unless Question::Answer.follows_type?(type, value) fail "Type doesn't match with question type!" end @answers[index] = value end