Class: VocaBuil::WordsSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/voca_buil/multi_check.rb,
lib/voca_buil/_stacks/_stacks_v2_260114/multi_check.rb

Direct Known Subclasses

AbbrevCheck::WordsSelector

Instance Method Summary collapse

Constructor Details

#initialize(word_log_file, options) ⇒ WordsSelector

Returns a new instance of WordsSelector.



178
179
180
181
182
# File 'lib/voca_buil/multi_check.rb', line 178

def initialize(word_log_file, options)
  @options = options
  # reverseオプションでファイル名を切り替え
  @word_log_file = options[:reverse] ? './word_log_j2e.yaml' : word_log_file
end

Instance Method Details

#select(w_num, a_num) ⇒ Object

w_num, a_numを受け取り、a_num+1個の単語を返す



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/voca_buil/multi_check.rb', line 185

def select(w_num, a_num)
  word_list = read_words(@options[:file])
  if File.exist?(@word_log_file)
    learning_log = YAML.load_file(@word_log_file)
    word_list.each do |word_entry|
      learning_log[word_entry[0]] = nil unless learning_log.key?(word_entry[0])
    end
    learning_log.delete_if { |word_key, _| word_list.none? { |word_entry| word_entry[0] == word_key } }
    File.write(@word_log_file, YAML.dump(learning_log))
  else
    learning_log = init_word_log(word_list)
    File.write(@word_log_file, YAML.dump(learning_log))
  end

  selected_words = select_least_correct_words(word_list)
  shuffle_words(selected_words, a_num)
end