mathy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{mathy/.gitignore → .gitignore} +0 -0
- data/.travis.yml +3 -0
- data/Gemfile.lock +2 -0
- data/Rakefile +7 -0
- data/bin/mathy +9 -0
- data/lib/mathy.rb +1 -3
- data/lib/mathy/console.rb +18 -2
- data/lib/mathy/difficulties/grade_two.rb +8 -0
- data/lib/mathy/game.rb +15 -14
- data/lib/mathy/operations/operation.rb +9 -3
- data/lib/mathy/player.rb +9 -0
- data/lib/mathy/verification.rb +8 -4
- data/lib/mathy/version.rb +1 -1
- data/mathy.gemspec +1 -0
- data/test/minitest_helper.rb +4 -0
- data/test/test_mathy.rb +11 -0
- metadata +26 -8
- data/bin/mathy.rb +0 -13
- data/lib/mathy/operations/addition.rb +0 -15
- data/lib/mathy/operations/subtraction.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ade07e7975c9605113ece23644be57c1786183b
|
4
|
+
data.tar.gz: b595bc96b10e6537dffe7d440f4ca2906dee1596
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06029b403ea8ac242731f141d5ac6a8dbf8fe60758641cb0dfd020074c4b4ad50790784ef5462e33c9187ca15c7f0d4aa032f8ca76522e6dd0a15b13c069837d
|
7
|
+
data.tar.gz: bd315a6e8644068e8da4256d8b48efd1639f687dc386fcf32a2ba562cb725add4e09dd0c5ef322adf084d902b973b1cb26660b9cad87486ffd72c6204146ccc9
|
File without changes
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
data/bin/mathy
ADDED
data/lib/mathy.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
require "mathy/version"
|
2
2
|
require 'mathy/console'
|
3
3
|
require 'mathy/verification'
|
4
|
+
require 'mathy/player'
|
4
5
|
require 'mathy/game'
|
5
6
|
require 'mathy/operations/operation'
|
6
|
-
require 'mathy/operations/addition'
|
7
|
-
require 'mathy/operations/subtraction'
|
8
|
-
|
9
7
|
require 'mathy/difficulties/grade_two'
|
10
8
|
|
11
9
|
module Mathy
|
data/lib/mathy/console.rb
CHANGED
@@ -14,15 +14,31 @@ module Mathy
|
|
14
14
|
operations.find { |operation| operation.matches?(selection) }
|
15
15
|
end
|
16
16
|
|
17
|
+
def difficulty?
|
18
|
+
Difficulties::GradeTwo.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def display_results(player, score, turns_played)
|
22
|
+
report ""
|
23
|
+
report "+++++++++++++++++++++++++++++++++++"
|
24
|
+
report "You got #{score}/#{turns_played}."
|
25
|
+
report "Good bye #{player.name}"
|
26
|
+
report "+++++++++++++++++++++++++++++++++++"
|
27
|
+
end
|
28
|
+
|
17
29
|
def prompt?(question)
|
18
|
-
|
30
|
+
report question
|
19
31
|
gets.strip
|
20
32
|
end
|
21
33
|
|
34
|
+
def report(message)
|
35
|
+
puts message
|
36
|
+
end
|
37
|
+
|
22
38
|
private
|
23
39
|
|
24
40
|
def clear_screen
|
25
|
-
|
41
|
+
report "\e[H\e[2J"
|
26
42
|
end
|
27
43
|
end
|
28
44
|
end
|
@@ -4,6 +4,14 @@ module Mathy
|
|
4
4
|
def next_operands
|
5
5
|
[rand(20), rand(20)].sort.reverse
|
6
6
|
end
|
7
|
+
|
8
|
+
def choose_operation(console)
|
9
|
+
verifier = Verification.new(console)
|
10
|
+
console.operation?([
|
11
|
+
Operations::Operation.new(self, "+", verifier),
|
12
|
+
Operations::Operation.new(self, "-", verifier)
|
13
|
+
])
|
14
|
+
end
|
7
15
|
end
|
8
16
|
end
|
9
17
|
end
|
data/lib/mathy/game.rb
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
module Mathy
|
2
2
|
class Game
|
3
|
-
def initialize(
|
4
|
-
@
|
3
|
+
def initialize(player, score = 0)
|
4
|
+
@player = player
|
5
5
|
@score = score
|
6
6
|
end
|
7
7
|
|
8
|
-
def play(
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
display_results(@name, @score, games_to_play)
|
8
|
+
def play(console)
|
9
|
+
turns_played = play_turns(console)
|
10
|
+
console.display_results(@player, @score, turns_played)
|
14
11
|
end
|
15
12
|
|
16
13
|
private
|
17
14
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
def play_turns(console)
|
16
|
+
turns_to_play = console.how_many_turns?
|
17
|
+
turns_to_play.times do
|
18
|
+
@score += 1 if operation(console).play_turn
|
19
|
+
end
|
20
|
+
turns_to_play
|
21
|
+
end
|
22
|
+
|
23
|
+
def operation(console)
|
24
|
+
@operation ||= console.difficulty?.choose_operation(console)
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
@@ -3,18 +3,24 @@ module Mathy
|
|
3
3
|
class Operation
|
4
4
|
attr_reader :key
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(difficulty, key, verification)
|
7
|
+
@difficulty = difficulty
|
8
8
|
@key = key
|
9
|
+
@verifier = verification
|
9
10
|
end
|
10
11
|
|
11
|
-
def play_turn
|
12
|
+
def play_turn
|
13
|
+
operands = @difficulty.next_operands
|
12
14
|
@verifier.check_answer("#{operands.join(" #{key} ")} = ", calculate(operands))
|
13
15
|
end
|
14
16
|
|
15
17
|
def matches?(other_key)
|
16
18
|
key == other_key
|
17
19
|
end
|
20
|
+
|
21
|
+
def calculate(operands)
|
22
|
+
operands.inject { |result, x| result.send(key.to_sym, x) }
|
23
|
+
end
|
18
24
|
end
|
19
25
|
end
|
20
26
|
end
|
data/lib/mathy/player.rb
ADDED
data/lib/mathy/verification.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
module Mathy
|
2
2
|
class Verification
|
3
|
+
def initialize(console)
|
4
|
+
@console = console
|
5
|
+
end
|
6
|
+
|
3
7
|
def check_answer(question, correct_answer)
|
4
|
-
|
5
|
-
|
8
|
+
@console.report ""
|
9
|
+
@console.report question
|
6
10
|
answer = gets
|
7
11
|
if answer.to_i == correct_answer
|
8
|
-
|
12
|
+
@console.report "Correct!"
|
9
13
|
return true
|
10
14
|
end
|
11
|
-
|
15
|
+
@console.report "The correct answer is #{correct_answer}."
|
12
16
|
false
|
13
17
|
end
|
14
18
|
end
|
data/lib/mathy/version.rb
CHANGED
data/mathy.gemspec
CHANGED
data/test/test_mathy.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mathy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mo khan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,32 +38,48 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: this is an application that my daughter and i are writing to help her
|
42
56
|
practice her math.
|
43
57
|
email:
|
44
58
|
- mo@mokhan.ca
|
45
59
|
executables:
|
46
|
-
- mathy
|
60
|
+
- mathy
|
47
61
|
extensions: []
|
48
62
|
extra_rdoc_files: []
|
49
63
|
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".travis.yml"
|
50
66
|
- Gemfile
|
51
67
|
- Gemfile.lock
|
52
68
|
- LICENSE.txt
|
53
69
|
- README.md
|
54
70
|
- Rakefile
|
55
|
-
- bin/mathy
|
71
|
+
- bin/mathy
|
56
72
|
- lib/mathy.rb
|
57
73
|
- lib/mathy/console.rb
|
58
74
|
- lib/mathy/difficulties/grade_two.rb
|
59
75
|
- lib/mathy/game.rb
|
60
|
-
- lib/mathy/operations/addition.rb
|
61
76
|
- lib/mathy/operations/operation.rb
|
62
|
-
- lib/mathy/
|
77
|
+
- lib/mathy/player.rb
|
63
78
|
- lib/mathy/verification.rb
|
64
79
|
- lib/mathy/version.rb
|
65
80
|
- mathy.gemspec
|
66
|
-
-
|
81
|
+
- test/minitest_helper.rb
|
82
|
+
- test/test_mathy.rb
|
67
83
|
homepage: ''
|
68
84
|
licenses:
|
69
85
|
- MIT
|
@@ -88,4 +104,6 @@ rubygems_version: 2.2.2
|
|
88
104
|
signing_key:
|
89
105
|
specification_version: 4
|
90
106
|
summary: a command line application to practice your math.
|
91
|
-
test_files:
|
107
|
+
test_files:
|
108
|
+
- test/minitest_helper.rb
|
109
|
+
- test/test_mathy.rb
|
data/bin/mathy.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'mathy'
|
3
|
-
|
4
|
-
verifier = Mathy::Verification.new
|
5
|
-
operations = [
|
6
|
-
Mathy::Operations::Addition.new(verifier),
|
7
|
-
Mathy::Operations::Subtraction.new(verifier)
|
8
|
-
]
|
9
|
-
|
10
|
-
console = Mathy::Console.new
|
11
|
-
game = Mathy::Game.new(console)
|
12
|
-
difficulty = Mathy::Difficulties::GradeTwo.new
|
13
|
-
game.play(console.how_many_turns?, console.operation?(operations), difficulty)
|