mathy 0.0.1 → 0.0.2

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: 5c519a5a7e7b51b1575c89d96e1adb11656d3b38
4
- data.tar.gz: 7f0b59a4f0a1853319eee609ce9745547b23a8f4
3
+ metadata.gz: 2ade07e7975c9605113ece23644be57c1786183b
4
+ data.tar.gz: b595bc96b10e6537dffe7d440f4ca2906dee1596
5
5
  SHA512:
6
- metadata.gz: 2f00ca5fa3c9a45402b074065e17cea90a50c433fec28124d00bb2f18ec3d12c91215f864d33bfedac751f15d3b89f7db28b4fb4a98237337b2571ac3e687c4b
7
- data.tar.gz: 76ce21412799aa03a79fc1ea84c0bd6078d0d83236273fc7a1b528b6f32c807a2d85f1b1d119797027cff02eb3f8f35b543b0ca1e506b75e4e49aa8a932382fa
6
+ metadata.gz: 06029b403ea8ac242731f141d5ac6a8dbf8fe60758641cb0dfd020074c4b4ad50790784ef5462e33c9187ca15c7f0d4aa032f8ca76522e6dd0a15b13c069837d
7
+ data.tar.gz: bd315a6e8644068e8da4256d8b48efd1639f687dc386fcf32a2ba562cb725add4e09dd0c5ef322adf084d902b973b1cb26660b9cad87486ffd72c6204146ccc9
File without changes
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
@@ -6,6 +6,7 @@ PATH
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ minitest (4.7.5)
9
10
  rake (10.1.0)
10
11
 
11
12
  PLATFORMS
@@ -14,4 +15,5 @@ PLATFORMS
14
15
  DEPENDENCIES
15
16
  bundler (~> 1.6)
16
17
  mathy!
18
+ minitest
17
19
  rake
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ end
7
+
8
+ task :default => :test
2
9
 
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mathy'
4
+
5
+ module Mathy
6
+ console = Console.new
7
+ game = Game.new(Player.new(console.greet))
8
+ game.play(console)
9
+ end
@@ -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
@@ -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
- puts question
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
- puts "\e[H\e[2J"
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
@@ -1,26 +1,27 @@
1
1
  module Mathy
2
2
  class Game
3
- def initialize(console, score = 0)
4
- @name = console.greet
3
+ def initialize(player, score = 0)
4
+ @player = player
5
5
  @score = score
6
6
  end
7
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)
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 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 "+++++++++++++++++++++++++++++++++++"
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(verification, key)
7
- @verifier = verification
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(operands)
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
@@ -0,0 +1,9 @@
1
+ module Mathy
2
+ class Player
3
+ attr_reader :name
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ end
8
+ end
9
+ end
@@ -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
- puts ""
5
- print question
8
+ @console.report ""
9
+ @console.report question
6
10
  answer = gets
7
11
  if answer.to_i == correct_answer
8
- print "Correct!"
12
+ @console.report "Correct!"
9
13
  return true
10
14
  end
11
- print "The correct answer is #{correct_answer}."
15
+ @console.report "The correct answer is #{correct_answer}."
12
16
  false
13
17
  end
14
18
  end
@@ -1,3 +1,3 @@
1
1
  module Mathy
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest"
23
24
  end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'mathy'
3
+
4
+ require 'minitest/autorun'
@@ -0,0 +1,11 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestMathy < MiniTest::Unit::TestCase
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::Mathy::VERSION
6
+ end
7
+
8
+ def test_it_does_something_useful
9
+ assert false
10
+ end
11
+ end
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.1
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-26 00:00:00.000000000 Z
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.rb
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.rb
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/operations/subtraction.rb
77
+ - lib/mathy/player.rb
63
78
  - lib/mathy/verification.rb
64
79
  - lib/mathy/version.rb
65
80
  - mathy.gemspec
66
- - mathy/.gitignore
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
@@ -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)
@@ -1,15 +0,0 @@
1
- module Mathy
2
- module Operations
3
- class Addition < Operation
4
- def initialize(verification)
5
- super(verification, "+")
6
- end
7
-
8
- def calculate(operands)
9
- operands.inject(0) do |result, x|
10
- result + x
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module Mathy
2
- module Operations
3
- class Subtraction < Operation
4
- def initialize(verification)
5
- super(verification, "-")
6
- end
7
-
8
- def calculate(operands)
9
- operands.inject(0) do |result, x|
10
- result + x
11
- end
12
- end
13
- end
14
- end
15
- end