Class: Mathy::Console
- Inherits:
-
Object
- Object
- Mathy::Console
- Defined in:
- lib/mathy/console.rb
Instance Method Summary collapse
- #difficulty? ⇒ Boolean
- #display_results(player, score, turns_played) ⇒ Object
- #greet ⇒ Object
- #how_many_turns? ⇒ Boolean
- #operation?(operations) ⇒ Boolean
- #prompt?(question) ⇒ Boolean
- #report(message) ⇒ Object
Instance Method Details
#difficulty? ⇒ Boolean
17 18 19 |
# File 'lib/mathy/console.rb', line 17 def difficulty? Difficulties::GradeTwo.new end |
#display_results(player, score, turns_played) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/mathy/console.rb', line 21 def display_results(player, score, turns_played) report "" report "+++++++++++++++++++++++++++++++++++" report "You got #{score}/#{turns_played}." report "Good bye #{player.name}" report "+++++++++++++++++++++++++++++++++++" end |
#greet ⇒ Object
3 4 5 6 |
# File 'lib/mathy/console.rb', line 3 def greet clear_screen prompt?('what is your name?') end |
#how_many_turns? ⇒ Boolean
8 9 10 |
# File 'lib/mathy/console.rb', line 8 def how_many_turns? prompt?("how many questions do you want?").to_i end |
#operation?(operations) ⇒ Boolean
12 13 14 15 |
# File 'lib/mathy/console.rb', line 12 def operation?(operations) selection = prompt?("choose operation? #{operations.map(&:key).flatten}") operations.find { |operation| operation.matches?(selection) } end |
#prompt?(question) ⇒ Boolean
29 30 31 32 |
# File 'lib/mathy/console.rb', line 29 def prompt?(question) report question gets.strip end |
#report(message) ⇒ Object
34 35 36 |
# File 'lib/mathy/console.rb', line 34 def report() puts end |