aritcaptcha 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.13.0
1
+ 1.14.0
data/aritcaptcha.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{aritcaptcha}
8
- s.version = "1.13.0"
8
+ s.version = "1.14.0"
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{2010-07-04}
12
+ s.date = %q{2010-07-05}
13
13
  s.description = %q{Arithmetic Captcha}
14
14
  s.email = %q{guilherme.ruby@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -10,22 +10,39 @@ module Aritcaptcha
10
10
 
11
11
  def aritcaptcha_tag(options={})
12
12
  equation_key = Time.now.to_i
13
- number1 = options[:one] || 50
14
- number2 = options[:two] || 50
15
- operation = options[:op] || OPERATIONS[rand(OPERATIONS.size)]
16
-
13
+ operations = {:add => "+", :sub => "-", :mul => "*", :div => "/"}
17
14
 
18
15
  equation, result = Aritcaptcha::Calculation.generate_calculation number1, number2, operation
19
-
20
-
21
16
  session[:equation] = [equation_key, eval(equation)]
17
+ puts "=========================================================="
18
+ puts equation
19
+ puts result
20
+ puts "=========================================================="
21
+
22
+ operator = nil
23
+ if options[:op] == nil
24
+ operator = operations.to_a[rand(operations.size)][1]
25
+ else
26
+ non_default_operations = {}
27
+ options[:op].each do |op|
28
+ non_default_operations[op] = operations[op]
29
+ end
30
+ operator = non_default_operations.to_a[rand(non_default_operations.size)][1]
31
+ end
32
+
33
+ options = {
34
+ :one => 50,
35
+ :two => 50
36
+ }.merge options
37
+
38
+ options[:op] = operator
22
39
 
23
40
  if options[:html]
24
- html_options = options[:html].inject([]){|dump, pair| dump << "#{pair[0]}=\"#{pair[1]}\""}
25
- html_options.join(" ")
41
+ options = options[:html].inject([]){|dump, pair| dump << "#{pair[0]}=\"#{pair[1]}\""}
42
+ options.join(" ")
26
43
  end
27
44
 
28
- html = "#{equation} = <input type='text' name='equation' #{html_options} />"
45
+ html = "#{equation} = <input type='text' name='equation' #{options} />"
29
46
  html << %{<input type="hidden" name="equation_key" value="#{equation_key}" />\n}
30
47
  html
31
48
  end
@@ -8,7 +8,7 @@ module Aritcaptcha
8
8
  equation = "#{number1} #{operation} #{number2}"
9
9
 
10
10
  # Division by zero
11
- return [nil, nil] if operation == "/" and number2.zero?
11
+ return [nil, nil] if operation == "/" and number1.zero? or number2.zero?
12
12
 
13
13
  result = eval("#{number1.to_f} #{operation} #{number2.to_f}")
14
14
 
@@ -17,6 +17,4 @@ module Aritcaptcha
17
17
 
18
18
  end
19
19
 
20
- end
21
-
22
- puts Aritcaptcha::Calculation.generate_calculation(10, 0, "/")
20
+ end
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: 35
4
+ hash: 47
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 13
8
+ - 14
9
9
  - 0
10
- version: 1.13.0
10
+ version: 1.14.0
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: 2010-07-04 00:00:00 -03:00
18
+ date: 2010-07-05 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency