Class: NiceTextCaptcha::Captcha

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCaptcha

Returns a new instance of Captcha.



8
9
10
11
12
13
14
15
16
17
# File 'lib/nice_text_captcha/captcha.rb', line 8

def initialize
  captcha = [
    Types::MathsQuestion,
    Types::LetterPositionQuestion,
    Types::WordsInListQuestion,
    Types::WordLengthQuestion,
  ].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



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

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



19
20
21
# File 'lib/nice_text_captcha/captcha.rb', line 19

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