Class: Captcha::Config
- Inherits:
-
Object
- Object
- Captcha::Config
- Defined in:
- lib/captcha/config.rb
Constant Summary collapse
- PRODUCTION =
false
- ROOT =
""
- ONE_DAY =
24 * 60 * 60
- @@options =
{ :password => 'captcha', :colors => { :background => '#FFFFFF', :font => '#080288' }, # number of captcha images to generate :count => PRODUCTION ? 500 : 10, :destination => "#{ROOT}public/images/captchas", :dimensions => { # canvas height (px) :height => 32, # canvas width (px) :width => 110 }, :generate_every => PRODUCTION ? ONE_DAY * 1 : ONE_DAY * 10000, # http://www.imagemagick.org/RMagick/doc/image2.html#implode :implode => 0.2, :letters => { # text baseline (px) :baseline => 25, # number of letters in captcha :count => 6, :ignore => ['a','e','i','o','u','l','j','q','v'], # font size (pts) :points => 38, # width of a character (used to decrease or increase space between characters) (px) :width => 17 }, :ttf => File.("#{File.dirname(__FILE__)}/../../resources/captcha.ttf"), # http://www.imagemagick.org/RMagick/doc/image3.html#wave :wave => { # range is used for randomness (px) :wavelength => (40..70), # distance between peak and valley of sin wave (px) :amplitude => 3 } }
Class Method Summary collapse
- .captchas ⇒ Object
- .codes ⇒ Object
- .exists?(code) ⇒ Boolean
- .last_modified ⇒ Object
- .options ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
52 53 54 |
# File 'lib/captcha/config.rb', line 52 def initialize(={}) @@options.merge!() end |
Class Method Details
.captchas ⇒ Object
56 57 58 |
# File 'lib/captcha/config.rb', line 56 def self.captchas Dir["#{@@options[:destination]}/*.jpg"] end |
.codes ⇒ Object
60 61 62 63 64 |
# File 'lib/captcha/config.rb', line 60 def self.codes self.captchas.collect do |f| File.basename f, '.jpg' end end |
.exists?(code) ⇒ Boolean
66 67 68 |
# File 'lib/captcha/config.rb', line 66 def self.exists?(code) File.exists?("#{@@options[:destination]}/#{code}.jpg") end |
.last_modified ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/captcha/config.rb', line 74 def self.last_modified file = self.captchas.first if file && File.exists?(file) File.mtime(file) else nil end end |
.options ⇒ Object
70 71 72 |
# File 'lib/captcha/config.rb', line 70 def self. @@options end |