Sha256: b8b056ef98ebdbace647330af03c59dce5e3a600629bdd76f83a118967f21653

Contents?: true

Size: 747 Bytes

Versions: 8

Compression:

Stored size: 747 Bytes

Contents

module Antispam
  class Challenge < ApplicationRecord
    before_create :generate

    def generate
      self.question = create_string
      self.answer = self.question
    end
    def create_string
      o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten
      (0...8).map { o[rand(o.length)] }.join
    end
    def get_image
      require "image_processing/vips"
      image = Vips::Image.text(self.answer, dpi: 300)
      image.draw_line(255, 5+rand(20).to_i, 5+rand(20).to_i, 150+rand(50).to_i, 10+rand(10).to_i)
    end
    def validate?(check)
      return false if self.answer.nil?
      result = false
      result = true if self.answer.downcase == check.downcase
      self.update_column(:answer,nil)
      return result
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
antispam-0.2.0 app/models/antispam/challenge.rb
antispam-0.1.7 app/models/antispam/challenge.rb
antispam-0.1.5 app/models/antispam/challenge.rb
antispam-0.1.4 app/models/antispam/challenge.rb
antispam-0.1.3 app/models/antispam/challenge.rb
antispam-0.1.2 app/models/antispam/challenge.rb
antispam-0.1.1 app/models/antispam/challenge.rb
antispam-0.1.0 app/models/antispam/challenge.rb