Class: Traptcha::Captcha
- Inherits:
-
Object
- Object
- Traptcha::Captcha
- Defined in:
- lib/traptcha/captcha.rb
Instance Attribute Summary collapse
-
#encryptor ⇒ Object
Returns the value of attribute encryptor.
-
#image_generator ⇒ Object
Returns the value of attribute image_generator.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(text = "") ⇒ Captcha
constructor
A new instance of Captcha.
- #to_png ⇒ Object
- #value ⇒ Object
Constructor Details
Instance Attribute Details
#encryptor ⇒ Object
Returns the value of attribute encryptor.
3 4 5 |
# File 'lib/traptcha/captcha.rb', line 3 def encryptor @encryptor end |
#image_generator ⇒ Object
Returns the value of attribute image_generator.
3 4 5 |
# File 'lib/traptcha/captcha.rb', line 3 def image_generator @image_generator end |
#text ⇒ Object
Returns the value of attribute text.
3 4 5 |
# File 'lib/traptcha/captcha.rb', line 3 def text @text end |
Class Method Details
.generate(options = {}) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/traptcha/captcha.rb', line 20 def generate( = {}) .reverse_merge! :valid_chars => Traptcha.valid_chars - Traptcha.ignored_chars, :length => Traptcha.default_length new generate_random_captcha() end |
.generate_random_captcha(options = {}) ⇒ Object
27 28 29 |
# File 'lib/traptcha/captcha.rb', line 27 def generate_random_captcha( = {}) [:length].times.map { [:valid_chars][rand([:valid_chars].length)] }.to_s end |
Instance Method Details
#to_png ⇒ Object
15 16 17 |
# File 'lib/traptcha/captcha.rb', line 15 def to_png @image_generator.new(text).output.to_blob end |
#value ⇒ Object
11 12 13 |
# File 'lib/traptcha/captcha.rb', line 11 def value @value ||= @encryptor.digest(text) end |