Class: Card

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/card.rb

Constant Summary collapse

MAX_CORRECT_ANSWERS =
5
MAX_INCORRECT_ANSWERS =
3
MAX_LEVENSHTEIN_DISTANCE =
1

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_reviewObject


20
21
22
23
# File 'app/models/card.rb', line 20

def self.for_review
  cards = where("review_date < ?", DateTime.now)
  cards.offset(rand(cards.count))
end

Instance Method Details

#review(translated) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/card.rb', line 25

def review(translated)
  typos = words_distanse(translated, original_text)

  if typos <= MAX_LEVENSHTEIN_DISTANCE
    handle_correct_answer
  else
    handle_incorrect_answer
  end

  { success: typos <= MAX_LEVENSHTEIN_DISTANCE, typos: typos }
end