gotcha 0.0.3 → 0.0.4
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/gotchas/backward_gotcha.rb +18 -0
- data/gotchas/sum_gotcha.rb +29 -0
- data/lib/gotcha/version.rb +1 -1
- metadata +5 -3
@@ -0,0 +1,18 @@
|
|
1
|
+
class BackwardGotcha < Gotcha::Base
|
2
|
+
|
3
|
+
MIN_STRING_LENGTH = 8
|
4
|
+
MAX_STRING_LENGTH = 15
|
5
|
+
|
6
|
+
CHARS = ('a'..'z').to_a + ('0'..'9').to_a
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
string_length = rand(MAX_STRING_LENGTH - MIN_STRING_LENGTH) + MIN_STRING_LENGTH
|
10
|
+
string = (0...string_length).collect { CHARS[Kernel.rand(CHARS.length)] }.join
|
11
|
+
|
12
|
+
@question = "What is '#{string}' backwards?"
|
13
|
+
@answer = string.reverse
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
Gotcha.register_type BackwardGotcha
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class SumGotcha < Gotcha::Base
|
2
|
+
|
3
|
+
DEFAULT_MIN = 0
|
4
|
+
DEFAULT_MAX = 20
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
rand1 = self.class.random_number_in_range
|
8
|
+
rand2 = self.class.random_number_in_range
|
9
|
+
@question = ["What is the sum of #{rand1} and #{rand2}?", "What is #{rand1} + #{rand2}?"].sample
|
10
|
+
@answer = rand1 + rand2
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def self.max
|
16
|
+
@@max ||= DEFAULT_MAX
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.min
|
20
|
+
@@min ||= DEFAULT_MIN
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.random_number_in_range
|
24
|
+
rand(self.max - self.min) + self.min
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
Gotcha.register_type SumGotcha
|
data/lib/gotcha/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gotcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Crepezzi
|
@@ -61,6 +61,8 @@ files:
|
|
61
61
|
- lib/gotcha/validation_error.rb
|
62
62
|
- lib/gotcha/version.rb
|
63
63
|
- lib/gotcha.rb
|
64
|
+
- gotchas/backward_gotcha.rb
|
65
|
+
- gotchas/sum_gotcha.rb
|
64
66
|
- spec/spec_helper.rb
|
65
67
|
has_rdoc: true
|
66
68
|
homepage: http://seejohnrun.github.com/gotcha/
|