math_captcha 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25c2b24c99855e42d71b25daa5a8258862ec6ea9
4
- data.tar.gz: 7ff04166b5f77bad2fd587b2916735bdcf25f80d
3
+ metadata.gz: ed68016f4e2e059bb029ec2cdc8de419e302ded4
4
+ data.tar.gz: e1bc302cffec6afbece99825b28d3ae8ab0059cc
5
5
  SHA512:
6
- metadata.gz: 931becb25605c9391a150b9f03dbea19df1bacc3aa07a756f522f2d436270948f5491c3d157ce6f6a150df6f966dbaa9d97f876492fc91fe46839a77b11bb528
7
- data.tar.gz: e1ce991e6673ac832ece621acb554964e405f4ff07a57d6f858ef8a9be962f77deee5a576b5b303e319e1c5fe214ced4707e27eabad1d70ae7bf0e1515bcc35f
6
+ metadata.gz: e88a46866ad80ef97a40370b8b5df7703466923041f76b95952d2902ae6eabb3c5573ff1c657574dd10d79cbe2a3a932e6cef55e1df15df3225f9e430b5e6779
7
+ data.tar.gz: ce6cb33684d6f3f1809407de1696fe4988b427fe694b84d6976df0ff0c1c6999f7ea403a160360af36aaf3e7cf2c0a855ffa3e91451bcb64365134d2cee2b6a2
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Math_captcha
2
2
 
3
3
  Math_captcha helps you generating localized captchas for forms. It presents a simple math operation that should be performed by user in order to ensure she is a human.
4
+
4
5
  This Gem is strongly inspired in visualcaptcha gem (https://github.com/kimenye/visualcaptcha)
5
6
 
6
7
  ## Installation
@@ -37,6 +38,15 @@ Add the following line in the file "app/controllers/application.rb"
37
38
  include MathCaptcha::ControllerHelpers
38
39
  end
39
40
 
41
+ ### I18n
42
+
43
+ math_captcha currently supports I18n for:
44
+
45
+ * English (en)
46
+ * Spanish (es)
47
+ * Basque (eu)
48
+
49
+ It defaults to I18n.locale or Spanish.
40
50
 
41
51
  ## Contributing
42
52
 
data/lib/math_captcha.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require "math_captcha/version"
2
3
  require "math_captcha/engine"
3
4
 
@@ -35,14 +36,14 @@ module MathCaptcha
35
36
  },
36
37
  'eu' => {
37
38
  0 => 'huts',
38
- 1 => 'bat',
39
- 2 => 'bi',
40
- 3 => 'hiru',
41
- 4 => 'lau',
39
+ 1 => 'bat',
40
+ 2 => 'bi',
41
+ 3 => 'hiru',
42
+ 4 => 'lau',
42
43
  5 => 'bost',
43
44
  6 => 'sei',
44
45
  7 => 'zazpi',
45
- 8 => 'zortzi',
46
+ 8 => 'zortzi',
46
47
  9 => 'bederatzi'
47
48
  },
48
49
  'en' => {
@@ -59,24 +60,23 @@ module MathCaptcha
59
60
  }
60
61
  }
61
62
 
62
- @ops = {
63
- 'es' => {
63
+ # temporary remove division operation
64
+
65
+ @ops = {
66
+ 'es' => {
64
67
  '+' => 'más',
65
68
  '-' => 'menos',
66
- '*' => 'por',
67
- '/' => 'entre'
69
+ '*' => 'por'
68
70
  },
69
71
  'eu' => {
70
72
  '+' => 'gehi',
71
73
  '-' => 'ken',
72
- '*' => 'bider',
73
- '/' => 'zati'
74
+ '*' => 'bider'
74
75
  },
75
76
  'en' => {
76
77
  '+' => 'plus',
77
78
  '-' => 'minus',
78
- '*' => 'times',
79
- '/' => 'divided by'
79
+ '*' => 'times'
80
80
  }
81
81
  }
82
82
  end
@@ -87,12 +87,15 @@ module MathCaptcha
87
87
  end
88
88
 
89
89
  def build_challenge(options={})
90
- digit1 = @numbers[rand(9)]
91
- digit2 = @numbers[rand(9)]
92
- op = @ops[locale].keys[rand(4)]
90
+ # loop to prevent negative numbers
91
+ begin
92
+ digit1 = @numbers[rand(9)]
93
+ digit2 = @numbers[rand(9)]
94
+ op = @ops[locale].keys[rand(4)]
93
95
 
96
+ value = eval("#{digit1}#{op}#{digit2}")
97
+ end while value < 0
94
98
 
95
- value = eval("#{digit1}#{op}#{digit2}")
96
99
  encrypted = MathCaptcha::Utils.generate_key(value)
97
100
  question = "#{@numbers_alpha[locale][digit1]} #{@ops[locale][op]} #{@numbers_alpha[locale][digit2]}"
98
101
  challenge = Challenge.new(question, value, encrypted, options)
@@ -6,7 +6,6 @@ module MathCaptcha
6
6
  session_challenge = session[:captcha]
7
7
  crypted_challenge = MathCaptcha::Utils.generate_key(params['captcha-value'])
8
8
  result = crypted_challenge === session_challenge
9
- pr "result #{result}"
10
9
  return result
11
10
  else
12
11
  return false
@@ -1,3 +1,3 @@
1
1
  module MathCaptcha
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: math_captcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tania Rubio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-02 00:00:00.000000000 Z
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler