humanizer 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/README.md +11 -2
- data/lib/humanizer.rb +17 -3
- data/lib/humanizer/version.rb +1 -1
- metadata +6 -7
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -46,6 +46,14 @@ You can just have a simple attribute on your model and use it to bypass the vali
|
|
46
46
|
require_human_on :create, :unless => :bypass_humanizer
|
47
47
|
|
48
48
|
Now when bypass_humanizer is true, validation will be skipped.
|
49
|
+
|
50
|
+
## Reloading questions
|
51
|
+
|
52
|
+
In case you want to give your users the option to change the question, there's a #change_humanizer_question method to help you.
|
53
|
+
|
54
|
+
To make sure the current question doesn't get asked again, you can pass the current question id to the method. For example:
|
55
|
+
|
56
|
+
@user.change_humanizer_question(params[:user][:humanizer_question_id])
|
49
57
|
|
50
58
|
## Live sites
|
51
59
|
|
@@ -65,5 +73,6 @@ Humanizer is licensed under the MIT License, for more details see the LICENSE fi
|
|
65
73
|
|
66
74
|
## Contributors
|
67
75
|
|
68
|
-
* [Florian Bertholin](
|
69
|
-
* [seogrady](
|
76
|
+
* [Florian Bertholin](https://github.com/Arkan)
|
77
|
+
* [seogrady](https://github.com/seogrady)
|
78
|
+
* [yairgo](https://github.com/yairgo)
|
data/lib/humanizer.rb
CHANGED
@@ -8,13 +8,19 @@ module Humanizer
|
|
8
8
|
attr_writer :humanizer_question_id
|
9
9
|
|
10
10
|
def humanizer_question
|
11
|
-
humanizer_questions[humanizer_question_id
|
11
|
+
humanizer_questions[humanizer_question_id]["question"]
|
12
12
|
end
|
13
13
|
|
14
14
|
def humanizer_question_id
|
15
|
-
@humanizer_question_id ||=
|
15
|
+
@humanizer_question_id ||= random_humanizer_question_id
|
16
16
|
end
|
17
17
|
|
18
|
+
def change_humanizer_question(current=nil)
|
19
|
+
@humanizer_question_ids = nil if humanizer_question_ids.compact.count == 1
|
20
|
+
humanizer_question_ids.delete(current) if current
|
21
|
+
@humanizer_question_id = random_humanizer_question_id
|
22
|
+
end
|
23
|
+
|
18
24
|
def humanizer_correct_answer?
|
19
25
|
humanizer_answer && humanizer_answers_for_id(humanizer_question_id).include?(humanizer_answer.downcase)
|
20
26
|
end
|
@@ -25,6 +31,14 @@ module Humanizer
|
|
25
31
|
@humanizer_questions ||= I18n.translate("humanizer.questions")
|
26
32
|
end
|
27
33
|
|
34
|
+
def humanizer_question_ids
|
35
|
+
@humanizer_question_ids ||= (0...humanizer_questions.count).to_a
|
36
|
+
end
|
37
|
+
|
38
|
+
def random_humanizer_question_id
|
39
|
+
humanizer_question_ids[rand(humanizer_question_ids.count)]
|
40
|
+
end
|
41
|
+
|
28
42
|
def humanizer_answers_for_id(id)
|
29
43
|
question = humanizer_questions[id.to_i]
|
30
44
|
Array(question["answer"] || question["answers"]).map { |a| a.to_s.downcase }
|
@@ -43,4 +57,4 @@ module Humanizer
|
|
43
57
|
|
44
58
|
end
|
45
59
|
|
46
|
-
end
|
60
|
+
end
|
data/lib/humanizer/version.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 2
|
7
|
-
-
|
7
|
+
- 4
|
8
8
|
- 0
|
9
|
-
version: 2.
|
9
|
+
version: 2.4.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Antti Akonniemi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-15 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -56,14 +56,13 @@ dependencies:
|
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
segments:
|
58
58
|
- 2
|
59
|
+
- 3
|
59
60
|
- 0
|
60
|
-
|
61
|
-
- beta
|
62
|
-
version: 2.0.0.beta
|
61
|
+
version: 2.3.0
|
63
62
|
type: :development
|
64
63
|
version_requirements: *id003
|
65
64
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
65
|
+
name: activemodel
|
67
66
|
prerelease: false
|
68
67
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
68
|
none: false
|