Class: StupidCaptcha::Captcha

Inherits:
Object
  • Object
show all
Includes:
StupidCaptcha
Defined in:
lib/stupid_captcha.rb

Constant Summary

Constants included from StupidCaptcha

GEM_ROOT, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StupidCaptcha

#backgrounds, #check, #encrypt, #files, #fonts, #random_string, #salt, setup

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



68
69
70
# File 'lib/stupid_captcha.rb', line 68

def hash
  @hash
end

#imgObject

Returns the value of attribute img.



68
69
70
# File 'lib/stupid_captcha.rb', line 68

def img
  @img
end

#textObject

Returns the value of attribute text.



68
69
70
# File 'lib/stupid_captcha.rb', line 68

def text
  @text
end

Instance Method Details

#renderObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/stupid_captcha.rb', line 70

def render
    icon = Magick::Image.read(backgrounds.sample).first

    drawable = Magick::Draw.new
    drawable.pointsize = 32.0
    drawable.font = fonts.sample
    drawable.fill = colors.sample
    drawable.gravity = Magick::CenterGravity

    # Tweak the font to draw slightly up and left from the center
    #        drawable.annotate(icon, 0, 0, -3, -6, @order.quantity.to_s)
    drawable.annotate(icon, 0, 0, 0,0, text)

    img = icon
end

#resetObject



86
87
88
89
90
# File 'lib/stupid_captcha.rb', line 86

def reset
  @text = random_string(rand(3)+5)
  @hash = encrypt(text, salt)
  @img = render
end

#to_blobObject



92
93
94
# File 'lib/stupid_captcha.rb', line 92

def to_blob
  img.to_blob
end