aritcaptcha 1.20.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/aritcaptcha.gemspec +19 -22
- data/lib/aritcaptcha.rb +1 -2
- data/lib/aritcaptcha/aritcaptcha_helper.rb +7 -7
- data/lib/aritcaptcha/aritcaptcha_verify.rb +2 -2
- data/lib/aritcaptcha/calculation.rb +9 -1
- data/spec/aritcaptcha_spec.rb +19 -19
- data/spec/spec_helper.rb +1 -7
- data/tags +19 -0
- metadata +8 -10
- data/.gitignore +0 -21
- data/spec/aritcaptcha_helper_spec.rb +0 -11
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.1
|
data/aritcaptcha.gemspec
CHANGED
@@ -1,47 +1,44 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{aritcaptcha}
|
8
|
-
s.version = "
|
8
|
+
s.version = "2.0.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Guilherme Nascimento"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-05-09}
|
13
13
|
s.description = %q{Arithmetic Captcha}
|
14
14
|
s.email = %q{guilherme.ruby@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
"spec/spec_helper.rb"
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"aritcaptcha.gemspec",
|
26
|
+
"lib/aritcaptcha.rb",
|
27
|
+
"lib/aritcaptcha/aritcaptcha_helper.rb",
|
28
|
+
"lib/aritcaptcha/aritcaptcha_verify.rb",
|
29
|
+
"lib/aritcaptcha/calculation.rb",
|
30
|
+
"spec/aritcaptcha_spec.rb",
|
31
|
+
"spec/spec.opts",
|
32
|
+
"spec/spec_helper.rb",
|
33
|
+
"tags"
|
35
34
|
]
|
36
35
|
s.homepage = %q{http://github.com/guinascimento/aritcaptcha}
|
37
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
38
36
|
s.require_paths = ["lib"]
|
39
37
|
s.rubygems_version = %q{1.3.7}
|
40
38
|
s.summary = %q{Arithmetic Captcha}
|
41
39
|
s.test_files = [
|
42
|
-
"spec/
|
43
|
-
|
44
|
-
"spec/spec_helper.rb"
|
40
|
+
"spec/aritcaptcha_spec.rb",
|
41
|
+
"spec/spec_helper.rb"
|
45
42
|
]
|
46
43
|
|
47
44
|
if s.respond_to? :specification_version then
|
data/lib/aritcaptcha.rb
CHANGED
@@ -29,15 +29,15 @@ module Aritcaptcha
|
|
29
29
|
session[:equation] = [equation_key, eval(equation)]
|
30
30
|
|
31
31
|
if options[:html]
|
32
|
-
options = options[:html].inject([]){|dump, pair| dump << "#{pair[0]}=\"#{pair[1]}\""}
|
32
|
+
options = options[:html].inject([]) { |dump, pair| dump << "#{pair[0]}=\"#{pair[1]}\"" }
|
33
33
|
options = options.join(" ")
|
34
34
|
end
|
35
35
|
|
36
36
|
html = ""
|
37
37
|
if options[:format] == "image"
|
38
38
|
session[:image] = equation_key
|
39
|
-
|
40
|
-
html << "<img src=\"
|
39
|
+
img = generate_image equation_key, equation
|
40
|
+
html << "<img src=\"/images/aritcaptcha/#{img}\" style='vertical-align:top;' /> <input type=\"text\" name=\"equation\" size=\"3\" style='vertical-align:top;' #{options} />"
|
41
41
|
else
|
42
42
|
html << "#{equation} = <input type=\"text\" name=\"equation\" style='vertical-align:top;' size=\"3\" #{options} /></div>"
|
43
43
|
end
|
@@ -47,7 +47,7 @@ module Aritcaptcha
|
|
47
47
|
|
48
48
|
def generate_image(equation_key, equation)
|
49
49
|
relative_name = "#{equation_key}.png"
|
50
|
-
full_path = "#{Rails.root}/public/images/#{relative_name}"
|
50
|
+
full_path = "#{Rails.root}/public/images/aritcaptcha/#{relative_name}"
|
51
51
|
|
52
52
|
unless File.file?(full_path)
|
53
53
|
image = Magick::Image.new(85, 25)
|
@@ -63,9 +63,9 @@ module Aritcaptcha
|
|
63
63
|
self.pointsize = 20
|
64
64
|
end
|
65
65
|
image.write(full_path)
|
66
|
-
|
67
|
-
|
66
|
+
end
|
67
|
+
relative_name
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
end
|
71
|
+
end
|
@@ -13,9 +13,9 @@ module Aritcaptcha
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def clean image
|
16
|
-
|
16
|
+
unless image == nil
|
17
17
|
relative_name = "#{image}.png"
|
18
|
-
full_path = "#{Rails.root}/public/images/#{relative_name}"
|
18
|
+
full_path = "#{Rails.root}/public/images/aritcaptcha/#{relative_name}"
|
19
19
|
File.delete(full_path)
|
20
20
|
end
|
21
21
|
end
|
@@ -2,7 +2,7 @@ module Aritcaptcha
|
|
2
2
|
|
3
3
|
class Calculation
|
4
4
|
|
5
|
-
def self.generate_calculation number1, number2, operator
|
5
|
+
def self.generate_calculation number1, number2, operator, &block
|
6
6
|
# Division by zero
|
7
7
|
return [nil, nil] if operator == "/" and number1.zero? or number2.zero?
|
8
8
|
|
@@ -12,6 +12,14 @@ module Aritcaptcha
|
|
12
12
|
equation = "#{number1} #{operator} #{number2}"
|
13
13
|
result = eval("#{number1.to_f} #{operator} #{number2.to_f}")
|
14
14
|
|
15
|
+
if result.infinite?
|
16
|
+
# over and over again untill !infnite
|
17
|
+
number1 = rand(number1)
|
18
|
+
number2 = rand(number2)
|
19
|
+
result = eval("#{number1.to_f} #{operator} #{number2.to_f}")
|
20
|
+
end
|
21
|
+
|
22
|
+
result = (result == result.floor) ? result.to_i : result
|
15
23
|
[equation, result]
|
16
24
|
end
|
17
25
|
|
data/spec/aritcaptcha_spec.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Aritcaptcha" do
|
4
|
+
it "should return the correct sum of its arguments" do
|
5
|
+
Aritcaptcha::Calculation.generate_calculation(10, 10, "+").should have(2).items
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return the subtraction of its arguments" do
|
9
|
+
Aritcaptcha::Calculation.generate_calculation(20, 10, "-").should have(2).items
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return the division of its arguments" do
|
13
|
+
Aritcaptcha::Calculation.generate_calculation(10, 2, "/").should have(2).items
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return the multiplication of its arguments" do
|
17
|
+
Aritcaptcha::Calculation.generate_calculation(10, 10, "*").should have(2).items
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,4 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
require 'aritcaptcha/calculation'
|
4
|
-
require 'aritcaptcha/aritcaptcha_helper'
|
5
|
-
require 'spec'
|
6
|
-
require 'spec/autorun'
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
4
|
+
require 'aritcaptcha/calculation'
|
data/tags
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
1279032088
|
2
|
+
ADD /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_helper.rb ADD =
|
3
|
+
Aritcaptcha /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_helper.rb module Aritcaptcha
|
4
|
+
Aritcaptcha /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_verify.rb module Aritcaptcha
|
5
|
+
Aritcaptcha /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/calculation.rb module Aritcaptcha
|
6
|
+
AritcaptchaHelper /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_helper.rb module AritcaptchaHelper
|
7
|
+
AritcaptchaVerify /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_verify.rb module AritcaptchaVerify
|
8
|
+
Calculation /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/calculation.rb class Calculation
|
9
|
+
DIV /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_helper.rb DIV =
|
10
|
+
MUL /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_helper.rb MUL =
|
11
|
+
OPERATIONS /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_helper.rb OPERATIONS =
|
12
|
+
SOLV /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_verify.rb SOLV =
|
13
|
+
SOLV_KEY /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_verify.rb SOLV_KEY =
|
14
|
+
SUB /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_helper.rb SUB =
|
15
|
+
aritcaptcha_tag /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_helper.rb def aritcaptcha_tag
|
16
|
+
clean /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_verify.rb def clean
|
17
|
+
generate_calculation /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/calculation.rb def self.generate_calculation
|
18
|
+
generate_image /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_helper.rb def generate_image
|
19
|
+
verify_aritcaptcha /home/guilherme/Projetos/aritcaptcha/lib/aritcaptcha/aritcaptcha_verify.rb def verify_aritcaptcha
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aritcaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
-
-
|
8
|
-
- 20
|
7
|
+
- 2
|
9
8
|
- 0
|
10
|
-
|
9
|
+
- 1
|
10
|
+
version: 2.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Guilherme Nascimento
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-05-09 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -45,7 +45,6 @@ extra_rdoc_files:
|
|
45
45
|
- README.rdoc
|
46
46
|
files:
|
47
47
|
- .document
|
48
|
-
- .gitignore
|
49
48
|
- LICENSE
|
50
49
|
- README.rdoc
|
51
50
|
- Rakefile
|
@@ -55,17 +54,17 @@ files:
|
|
55
54
|
- lib/aritcaptcha/aritcaptcha_helper.rb
|
56
55
|
- lib/aritcaptcha/aritcaptcha_verify.rb
|
57
56
|
- lib/aritcaptcha/calculation.rb
|
58
|
-
- spec/aritcaptcha_helper_spec.rb
|
59
57
|
- spec/aritcaptcha_spec.rb
|
60
58
|
- spec/spec.opts
|
61
59
|
- spec/spec_helper.rb
|
60
|
+
- tags
|
62
61
|
has_rdoc: true
|
63
62
|
homepage: http://github.com/guinascimento/aritcaptcha
|
64
63
|
licenses: []
|
65
64
|
|
66
65
|
post_install_message:
|
67
|
-
rdoc_options:
|
68
|
-
|
66
|
+
rdoc_options: []
|
67
|
+
|
69
68
|
require_paths:
|
70
69
|
- lib
|
71
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -94,6 +93,5 @@ signing_key:
|
|
94
93
|
specification_version: 3
|
95
94
|
summary: Arithmetic Captcha
|
96
95
|
test_files:
|
97
|
-
- spec/aritcaptcha_helper_spec.rb
|
98
96
|
- spec/aritcaptcha_spec.rb
|
99
97
|
- spec/spec_helper.rb
|
data/.gitignore
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
# require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
#
|
3
|
-
# describe "AritcaptchaHelper" do
|
4
|
-
# before :each do
|
5
|
-
# @helper = Aritcaptcha::AritcaptchaHelper
|
6
|
-
# end
|
7
|
-
#
|
8
|
-
# it "should accept two numbers and the operator as argument" do
|
9
|
-
# puts Aritcaptcha::AritcaptchaHelper.aritcaptcha_tag :html => { :one => "10", :two => "10", :operation => "+" }
|
10
|
-
# end
|
11
|
-
# end
|