Class: ScaleTest

Inherits:
Test
  • Object
show all
Defined in:
lib/jungi/classes.rb

Overview

Basic Scale5 Test Class

Constant Summary collapse

QUESTIONS =

Default scale questions

['very not dead|very dead', 'very not alive|very alive']

Instance Method Summary collapse

Methods inherited from Test

#answer, #answer=, #answers, #done?, #finished?, #get_question, #initialize, #method_missing, #out_of_index?, #question

Constructor Details

This class inherits a constructor from Test

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Test

Instance Method Details

#randomize!Object

Randomize the answers to a scale test



194
195
196
197
198
199
# File 'lib/jungi/classes.rb', line 194

def randomize!
  self.class.const_get(:QUESTIONS).length.times do |num|
    set_answer(num, rand(1..5))
  end
  nil
end

#resultObject

Default results for scale test



202
203
204
205
206
207
208
209
210
211
212
# File 'lib/jungi/classes.rb', line 202

def result
  fail 'Not ready yet!' unless self.finished?
  val = @answers[1] - @answers[0]
  if val < 0
    "Sad to hear you're dead."
  elsif val > 0
    "Good to hear you're alive!"
  else
    "You're hard to figure out."
  end
end

#set_answer(index, value) ⇒ Object

Set question answer to value



187
188
189
190
191
# File 'lib/jungi/classes.rb', line 187

def set_answer(index, value)
  self.out_of_index? index
  fail "#{value} is not a scale!" unless Question::Answer.scale?(value)
  @answers[index] = value
end