Class: Captcher::Captchas::CodeCaptcha

Inherits:
BaseCaptcha show all
Defined in:
lib/captcher/captchas/code_captcha.rb

Constant Summary collapse

SPECIAL_CHAR_CODES =
(91..96).freeze

Constants inherited from BaseCaptcha

BaseCaptcha::SESSION_KEY

Instance Attribute Summary

Attributes inherited from BaseCaptcha

#config, #payload

Instance Method Summary collapse

Methods inherited from BaseCaptcha

#initialize, #own_config, restore, restore_or_create, #store

Constructor Details

This class inherits a constructor from Captcher::BaseCaptcha

Instance Method Details

#after_initializeObject

rubocop:disable Naming/MemoizedInstanceVariableName



9
10
11
# File 'lib/captcher/captchas/code_captcha.rb', line 9

def after_initialize
  @payload ||= random_text
end

#represent(format = :html, options = {}) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



15
16
17
# File 'lib/captcher/captchas/code_captcha.rb', line 15

def represent(format = :html, options = {})
  Captcher::TextImage.new(@payload, own_config).generate
end

#validate(confirmation) ⇒ Object

rubocop:enable Lint/UnusedMethodArgument



20
21
22
# File 'lib/captcher/captchas/code_captcha.rb', line 20

def validate(confirmation)
  confirmation.to_s.strip.casecmp(@payload).zero?
end