class Captcher::Captchas::CodeCaptcha
Constants
- SPECIAL_CHAR_CODES
Public Instance Methods
after_initialize()
click to toggle source
rubocop:disable Naming/MemoizedInstanceVariableName
# File lib/captcher/captchas/code_captcha.rb, line 9 def after_initialize @payload ||= random_text end
represent(format = :html, options = {})
click to toggle source
rubocop:disable Lint/UnusedMethodArgument
# File lib/captcher/captchas/code_captcha.rb, line 15 def represent(format = :html, options = {}) Captcher::TextImage.new(@payload, own_config).generate end
validate(confirmation)
click to toggle source
rubocop:enable Lint/UnusedMethodArgument
# File lib/captcher/captchas/code_captcha.rb, line 20 def validate(confirmation) confirmation.to_s.strip.casecmp(@payload).zero? end
Private Instance Methods
random_char()
click to toggle source
# File lib/captcher/captchas/code_captcha.rb, line 30 def random_char random_char_code.chr end
random_char_code()
click to toggle source
# File lib/captcher/captchas/code_captcha.rb, line 34 def random_char_code char_code = ("A".ord + (rand * ("z".ord - "A".ord)).floor) char_code.in?(SPECIAL_CHAR_CODES) ? random_char_code : char_code end
random_text()
click to toggle source
# File lib/captcher/captchas/code_captcha.rb, line 26 def random_text @random_text ||= Array.new(own_config[:count]).map { random_char }.join("") end