Sha256: 3823696a9ee8e5798401ea8dc955e59cb4e0fa4dd4b7b6097186ebd084e2ce34

Contents?: true

Size: 773 Bytes

Versions: 11

Compression:

Stored size: 773 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

11 entries across 11 versions & 1 rubygems

Version Path
antispam-0.3.3 app/models/antispam/challenge.rb
antispam-0.3.2 app/models/antispam/challenge.rb
antispam-0.3.1 app/models/antispam/challenge.rb
antispam-0.3.0 app/models/antispam/challenge.rb
antispam-0.2.11 app/models/antispam/challenge.rb
antispam-0.2.10 app/models/antispam/challenge.rb
antispam-0.2.8 app/models/antispam/challenge.rb
antispam-0.2.6 app/models/antispam/challenge.rb
antispam-0.2.5 app/models/antispam/challenge.rb
antispam-0.2.4 app/models/antispam/challenge.rb
antispam-0.2.3 app/models/antispam/challenge.rb