Class: NiceTextCaptcha::Types::WordLengthQuestion

Inherits:
DefaultQuestion show all
Defined in:
lib/nice_text_captcha/types/word_length_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

#initializeWordLengthQuestion

Returns a new instance of WordLengthQuestion.



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

def initialize
  word = [ANIMALS + COLOURS].flatten.rand
  answer = word.length
  
  @question = format_question(randomly_quote_and_capitalise(word))
  @answers = [answer, number_to_word(answer)]
end

Instance Method Details

#format_question(word) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/nice_text_captcha/types/word_length_question.rb', line 11

def format_question(word)
  [
    "How many letters are in the word %s?" % word,
    "How many letters are there in the word %s?" % word,
    "How many letters are there in %s?" % word,
    "In the word %s, how many letters are there?" % word,
  ].rand
end