Class: Mathy::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/mathy/console.rb

Instance Method Summary collapse

Instance Method Details

#difficulty?Boolean

Returns:

  • (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

#greetObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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(message)
  puts message
end