Created
December 15, 2017 11:34
-
-
Save GeorgeBramus/139fd5813b9fa1f130036d5bc006166e to your computer and use it in GitHub Desktop.
misspelling output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CheckCardAndUpdate | |
# ... | |
def call | |
card = Card.find(context.card_id) | |
context.message = if coincides?(card.original_text, context.custom_original_text) | |
correct_answer(card) | |
'right' | |
else | |
incorrect_answer(card) | |
context.misspelling = coincides?(card.original_text, context.custom_original_text) | |
'wrong' | |
end | |
end | |
# ... | |
private def coincides?(card_original_text, custom_original_text) | |
DamerauLevenshtein.distance(card_original_text.mb_chars.downcase.to_s, custom_original_text.mb_chars.downcase.to_s) == 0 | |
end | |
# ... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HomeController < ApplicationController | |
# ... | |
def check | |
result = CheckCardAndUpdate.call( | |
custom_original_text: params[:original_text], | |
card_id: params[:id] | |
) | |
@misspelling = result.misspelling if result.misspelling | |
flash[:notice] = result.message | |
redirect_to action: :index | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ ... | |
- if flash[:notice] | |
#error_explanation class="#{flash[:notice]}" | |
h2 Результат | |
ul | |
li = flash[:notice] | |
- if @misspelling | |
= @misspelling | |
/ форма на главную страницу | |
/ ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment