Class: NiceTextCaptcha::Types::MathsQuestion

Inherits:
DefaultQuestion show all
Defined in:
lib/nice_text_captcha/types/maths_question.rb

Constant Summary

Constants inherited from DefaultQuestion

DefaultQuestion::ANIMALS, DefaultQuestion::COLOURS

Instance Attribute Summary

Attributes inherited from DefaultQuestion

#answers, #question

Instance Method Summary collapse

Constructor Details

#initializeMathsQuestion

Returns a new instance of MathsQuestion.



3
4
5
6
7
8
9
10
# File 'lib/nice_text_captcha/types/maths_question.rb', line 3

def initialize
  number_1 = one_to_nine
  number_2 = one_to_nine
  answer = number_1 + number_2
  
  @question = format_question(number_or_word(number_1), number_or_word(number_2))
  @answers = [answer, number_to_word(answer)]
end

Instance Method Details

#format_question(one, two) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/nice_text_captcha/types/maths_question.rb', line 12

def format_question(one, two)
  [
    "What is %s plus %s?" % [one, two],
    "What is %s + %s?" % [one, two],
    "What is %s added to %s?" % [one, two],
    "What do you get if you add the numbers %s and %s?" % [one, two],
    "What is the result of adding %s and %s?" % [one, two],
  ].rand
end