Sha256: 79695d471a9d06fd1446d121fc960836d8c210ff877e0935895e007d9bcd40e6
Contents?: true
Size: 1.02 KB
Versions: 6
Compression:
Stored size: 1.02 KB
Contents
module Captcher module Captchas class CodeCaptcha < BaseCaptcha SPECIAL_CHAR_CODES = (91..96).freeze self.name = :code_captcha # rubocop:disable Naming/MemoizedInstanceVariableName def after_initialize @payload ||= random_text end # rubocop:enable Naming/MemoizedInstanceVariableName # rubocop:disable Lint/UnusedMethodArgument def represent(format = :html, options = {}) Captcher::TextImage.new(@payload, own_config).generate end # rubocop:enable Lint/UnusedMethodArgument def validate(confirmation) confirmation.to_s.strip.casecmp(@payload).zero? end private def random_text @random_text ||= Array.new(own_config[:count]).map { random_char }.join("") end def random_char random_char_code.chr end 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 end end end
Version data entries
6 entries across 6 versions & 1 rubygems