Module: TextCaptcha::Validation::InstanceMethods
- Defined in:
- lib/text_captcha/validation.rb
Instance Method Summary collapse
-
#all_challenges ⇒ Object
Return all questions.
-
#challenge ⇒ Object
Return the question string.
-
#challenge_answers ⇒ Object
Return all accepted answers.
-
#challenge_id ⇒ Object
Return the question id.
-
#current_challenge ⇒ Object
Return an array with the current question and its answers.
-
#valid_challenge_answer? ⇒ Boolean
Detect if the answer is correct.
Instance Method Details
#all_challenges ⇒ Object
Return all questions.
95 96 97 |
# File 'lib/text_captcha/validation.rb', line 95 def all_challenges @all_challenges ||= I18n.t("text_captcha.challenges") end |
#challenge ⇒ Object
Return the question string.
79 80 81 |
# File 'lib/text_captcha/validation.rb', line 79 def challenge current_challenge.first end |
#challenge_answers ⇒ Object
Return all accepted answers.
84 85 86 |
# File 'lib/text_captcha/validation.rb', line 84 def challenge_answers current_challenge.last end |
#challenge_id ⇒ Object
Return the question id. If none is assigned it chooses on randomly.
90 91 92 |
# File 'lib/text_captcha/validation.rb', line 90 def challenge_id @challenge_id ||= Kernel.rand(all_challenges.count) end |
#current_challenge ⇒ Object
Return an array with the current question and its answers.
74 75 76 |
# File 'lib/text_captcha/validation.rb', line 74 def current_challenge all_challenges[challenge_id.to_i] end |
#valid_challenge_answer? ⇒ Boolean
Detect if the answer is correct. Will also return true if TextCaptcha.enabled
is set to false
.
101 102 103 104 105 106 107 |
# File 'lib/text_captcha/validation.rb', line 101 def valid_challenge_answer? return false unless current_challenge return true unless TextCaptcha.enabled answers = challenge_answers.collect {|a| to_captcha(a)} !challenge_answer.blank? && answers.include?(to_captcha(challenge_answer)) end |