Class: AbbrevCheck::BaseCheck

Inherits:
VocaBuil::BaseCheck show all
Defined in:
lib/abbrev_checker/abbrev_check.rb

Constant Summary

Constants inherited from VocaBuil::BaseCheck

VocaBuil::BaseCheck::CHECK_LOG_FILE, VocaBuil::BaseCheck::WORD_LOG_FILE, VocaBuil::BaseCheck::WORD_LOG_FILE_J2E

Instance Method Summary collapse

Methods inherited from VocaBuil::BaseCheck

#init_word_log, #initialize, #make_answers, #print_answers, #select_least_correct_words, #shuffle_answers, #shuffle_words, #update_logs

Constructor Details

This class inherits a constructor from VocaBuil::BaseCheck

Instance Method Details

#check_results(words_shuffled, user_inputs, w_num) ⇒ Object

入力が正解と完全一致するか判定



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/abbrev_checker/abbrev_check.rb', line 34

def check_results(words_shuffled, user_inputs, w_num)
  results = {}
  [w_num, words_shuffled.size].min.times do |i|
    ans = words_shuffled[i]
    next if ans.nil?
    user_input = user_inputs[i]
    print "'#{user_input}' "
    correct_answer = @options[:reverse] ? ans[-1] : ans[1]
    if user_input == correct_answer
      print "true:  ".green
      t_or_f = 't'
    else
      print "false: ".red
      t_or_f = 'f'
    end
    p ans
    results[ans[0]] = t_or_f
  end
  results
end

#get_user_inputs(words_shuffled, w_num) ⇒ Object

選択肢を作らず、単語を直接入力させる



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/abbrev_checker/abbrev_check.rb', line 16

def get_user_inputs(words_shuffled, w_num)
  user_inputs = []
  words_shuffled.first(w_num).each_with_index do |ew, idx|
    break if ew.nil?
    question = "Q#{idx+1}: '#{ew[0]}' ? -> "
    if ENV['SIMPLE_CHECK_TEST']
      puts question
      user_inputs << ew[1] # テスト時は正解を自動入力
    else
      input = Thor::Shell::Basic.new.ask question
      user_input = input ? input.chomp.unicode_normalize(:nfkc) : ""
      user_inputs << user_input
    end
  end
  user_inputs
end

#runObject

runメソッドを上書き



56
57
58
59
60
61
62
63
# File 'lib/abbrev_checker/abbrev_check.rb', line 56

def run
  selector = WordsSelector.new(@word_log_file, @options)
  words_shuffled = selector.select(@options[:w_num], @options[:a_num])
  user_inputs = get_user_inputs(words_shuffled, @options[:w_num])
  results = check_results(words_shuffled, user_inputs, @options[:w_num])
  update_logs(results)
  results
end