Class: Antispam::Challenge
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Antispam::Challenge
- Defined in:
- app/models/antispam/challenge.rb
Instance Method Summary collapse
Instance Method Details
#create_string ⇒ Object
9 10 11 12 |
# File 'app/models/antispam/challenge.rb', line 9 def create_string o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten (0...8).map { o[rand(o.length)] }.join end |
#generate ⇒ Object
5 6 7 8 |
# File 'app/models/antispam/challenge.rb', line 5 def generate self.question = create_string self.answer = self.question end |
#get_image ⇒ Object
13 14 15 16 17 |
# File 'app/models/antispam/challenge.rb', line 13 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 |
#validate?(check) ⇒ Boolean
18 19 20 21 22 23 24 |
# File 'app/models/antispam/challenge.rb', line 18 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 |