Class: Keisanjaku::Modes::Drill
- Inherits:
-
Object
- Object
- Keisanjaku::Modes::Drill
- Defined in:
- lib/keisanjaku/modes/drill.rb
Instance Method Summary collapse
-
#initialize(width: nil, color: true, tolerance_percent: 1.0, output: $stdout) ⇒ Drill
constructor
A new instance of Drill.
- #run(input: $stdin) ⇒ Object
Constructor Details
#initialize(width: nil, color: true, tolerance_percent: 1.0, output: $stdout) ⇒ Drill
Returns a new instance of Drill.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/keisanjaku/modes/drill.rb', line 9 def initialize(width: nil, color: true, tolerance_percent: 1.0, output: $stdout) @width = width @color = color @generator = QuestionGenerator.new @judge = Judge.new(tolerance_percent: tolerance_percent) @procedure_checker = ProcedureChecker.new @output = output @score = 0 @streak = 0 @started_at = Time.now end |
Instance Method Details
#run(input: $stdin) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/keisanjaku/modes/drill.rb', line 21 def run(input: $stdin) operations = choose_operations(input) loop do question = @generator.next_question(operation: operations.sample) puts_fitted(question.prompt) attempt = operate_before_answer(input, question) break if attempt == :quit next if attempt == :next answer = attempt.answer || read_text_answer(input) break if answer.nil? || answer == "q" if answer == "g" show_demo(question) next end judge_answer(answer, question, attempt) end end |