mathy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/mathy.rb +13 -0
- data/lib/mathy.rb +12 -0
- data/lib/mathy/console.rb +28 -0
- data/lib/mathy/difficulties/grade_two.rb +9 -0
- data/lib/mathy/game.rb +26 -0
- data/lib/mathy/operations/addition.rb +15 -0
- data/lib/mathy/operations/operation.rb +20 -0
- data/lib/mathy/operations/subtraction.rb +15 -0
- data/lib/mathy/verification.rb +15 -0
- data/lib/mathy/version.rb +3 -0
- data/mathy.gemspec +23 -0
- data/mathy/.gitignore +22 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c519a5a7e7b51b1575c89d96e1adb11656d3b38
|
4
|
+
data.tar.gz: 7f0b59a4f0a1853319eee609ce9745547b23a8f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f00ca5fa3c9a45402b074065e17cea90a50c433fec28124d00bb2f18ec3d12c91215f864d33bfedac751f15d3b89f7db28b4fb4a98237337b2571ac3e687c4b
|
7
|
+
data.tar.gz: 76ce21412799aa03a79fc1ea84c0bd6078d0d83236273fc7a1b528b6f32c807a2d85f1b1d119797027cff02eb3f8f35b543b0ca1e506b75e4e49aa8a932382fa
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 mo khan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Mathy
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mathy'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mathy
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/mathy/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/mathy.rb
ADDED
@@ -0,0 +1,13 @@
|
|
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)
|
data/lib/mathy.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "mathy/version"
|
2
|
+
require 'mathy/console'
|
3
|
+
require 'mathy/verification'
|
4
|
+
require 'mathy/game'
|
5
|
+
require 'mathy/operations/operation'
|
6
|
+
require 'mathy/operations/addition'
|
7
|
+
require 'mathy/operations/subtraction'
|
8
|
+
|
9
|
+
require 'mathy/difficulties/grade_two'
|
10
|
+
|
11
|
+
module Mathy
|
12
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Mathy
|
2
|
+
class Console
|
3
|
+
def greet
|
4
|
+
clear_screen
|
5
|
+
prompt?('what is your name?')
|
6
|
+
end
|
7
|
+
|
8
|
+
def how_many_turns?
|
9
|
+
prompt?("how many questions do you want?").to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
def operation?(operations)
|
13
|
+
selection = prompt?("choose operation? #{operations.map(&:key).flatten}")
|
14
|
+
operations.find { |operation| operation.matches?(selection) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def prompt?(question)
|
18
|
+
puts question
|
19
|
+
gets.strip
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def clear_screen
|
25
|
+
puts "\e[H\e[2J"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/mathy/game.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Mathy
|
2
|
+
class Game
|
3
|
+
def initialize(console, score = 0)
|
4
|
+
@name = console.greet
|
5
|
+
@score = score
|
6
|
+
end
|
7
|
+
|
8
|
+
def play(games_to_play = 2, operation, difficulty)
|
9
|
+
games_to_play.times do
|
10
|
+
@score += 1 if operation.play_turn(difficulty.next_operands)
|
11
|
+
end
|
12
|
+
|
13
|
+
display_results(@name, @score, games_to_play)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def display_results(name, score, games_to_play)
|
19
|
+
puts ""
|
20
|
+
puts "+++++++++++++++++++++++++++++++++++"
|
21
|
+
puts "You got #{score}/#{games_to_play}."
|
22
|
+
puts "Good bye #{name}"
|
23
|
+
puts "+++++++++++++++++++++++++++++++++++"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Mathy
|
2
|
+
module Operations
|
3
|
+
class Operation
|
4
|
+
attr_reader :key
|
5
|
+
|
6
|
+
def initialize(verification, key)
|
7
|
+
@verifier = verification
|
8
|
+
@key = key
|
9
|
+
end
|
10
|
+
|
11
|
+
def play_turn(operands)
|
12
|
+
@verifier.check_answer("#{operands.join(" #{key} ")} = ", calculate(operands))
|
13
|
+
end
|
14
|
+
|
15
|
+
def matches?(other_key)
|
16
|
+
key == other_key
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Mathy
|
2
|
+
class Verification
|
3
|
+
def check_answer(question, correct_answer)
|
4
|
+
puts ""
|
5
|
+
print question
|
6
|
+
answer = gets
|
7
|
+
if answer.to_i == correct_answer
|
8
|
+
print "Correct!"
|
9
|
+
return true
|
10
|
+
end
|
11
|
+
print "The correct answer is #{correct_answer}."
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/mathy.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mathy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mathy"
|
8
|
+
spec.version = Mathy::VERSION
|
9
|
+
spec.authors = ["mo khan"]
|
10
|
+
spec.email = ["mo@mokhan.ca"]
|
11
|
+
spec.summary = %q{a command line application to practice your math.}
|
12
|
+
spec.description = %q{this is an application that my daughter and i are writing to help her practice her math.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/mathy/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mathy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mo khan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: this is an application that my daughter and i are writing to help her
|
42
|
+
practice her math.
|
43
|
+
email:
|
44
|
+
- mo@mokhan.ca
|
45
|
+
executables:
|
46
|
+
- mathy.rb
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/mathy.rb
|
56
|
+
- lib/mathy.rb
|
57
|
+
- lib/mathy/console.rb
|
58
|
+
- lib/mathy/difficulties/grade_two.rb
|
59
|
+
- lib/mathy/game.rb
|
60
|
+
- lib/mathy/operations/addition.rb
|
61
|
+
- lib/mathy/operations/operation.rb
|
62
|
+
- lib/mathy/operations/subtraction.rb
|
63
|
+
- lib/mathy/verification.rb
|
64
|
+
- lib/mathy/version.rb
|
65
|
+
- mathy.gemspec
|
66
|
+
- mathy/.gitignore
|
67
|
+
homepage: ''
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.2.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: a command line application to practice your math.
|
91
|
+
test_files: []
|