Class: NiceTextCaptcha::Captcha

Inherits:
Object
  • Object
show all
Defined in:
lib/nice_text_captcha/captcha.rb

Constant Summary collapse

NICE_TEXT_CAPTCHA_TYPE_DEFAULTS =
[
  Types::FixedQuestion,
  Types::MathsQuestion,
  Types::LetterPositionQuestion,
  Types::WordsInListQuestion,
  Types::WordLengthQuestion,
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCaptcha

Returns a new instance of Captcha.



16
17
18
19
20
# File 'lib/nice_text_captcha/captcha.rb', line 16

def initialize
  captcha = (NICE_TEXT_CAPTCHA_TYPES rescue NICE_TEXT_CAPTCHA_TYPE_DEFAULTS).rand.new
  @question = captcha.question
  @answers = captcha.answers
end

Instance Attribute Details

#answersObject (readonly)

Returns the value of attribute answers.



6
7
8
# File 'lib/nice_text_captcha/captcha.rb', line 6

def answers
  @answers
end

#questionObject (readonly)

Returns the value of attribute question.



5
6
7
# File 'lib/nice_text_captcha/captcha.rb', line 5

def question
  @question
end

Class Method Details

.hash(obj, answer) ⇒ Object



26
27
28
29
# File 'lib/nice_text_captcha/captcha.rb', line 26

def self.hash(obj, answer)
  str = obj.to_s + answer.to_s + ActionController::Base.session_options[:secret].to_s
  Digest::SHA2.hexdigest(str)
end

Instance Method Details

#encrypted_answers_for(object_name) ⇒ Object



22
23
24
# File 'lib/nice_text_captcha/captcha.rb', line 22

def encrypted_answers_for(object_name)
  answers.collect { |answer| Captcha.hash(object_name, answer) }
end