lib/language_cards/controllers/game.rb in language_cards-0.1.3 vs lib/language_cards/controllers/game.rb in language_cards-0.2.0
- old
+ new
@@ -4,20 +4,22 @@
class << self
include Helpers::ViewHelper
include Helpers::GameHelper
def render(correct:, incorrect:, title:, timer:, last:)
- _score = t('Game.ScoreMenu.Score') + ": %0.2d%" % calc_score(correct, incorrect)
+ _score = t('Game.ScoreMenu.Score') + ": %0.2d%%" % calc_score(correct, incorrect)
_timer = [((t('Timer.Timer') + ": " + timer.ha) if timer.time?), nil, timer.h]
_mexit = t 'Menu.Exit'
- view = ERB.new(IO.read(File.expand_path('../view/game.erb', __dir__)))
+ view = File.expand_path('../view/game.erb', __dir__).
+ ᐅ( IO.method :read ).
+ ᐅ ERB.method :new
view.result(binding)
end
- def process(card_collection, mode)
- ic = struct_data.new(card_collection, mode.peek)
+ def process(cards, mode)
+ ic = struct_data.new(cards, mode)
ic.get_input
{
correct: ic.valid?,
last: ic.valid? ? ic.correct_msg : ic.incorrect_msg
}
@@ -28,23 +30,30 @@
def input
@input
end
def get_input
- @input ||= CLI.ask("#{I18n.t('Game.TypeThis')} #{collection.mapped_as}: #{display}")
+ @input ||= CLI.ask("#{I18n.t('Game.TypeThis')}: #{display}")
end
- def comp_bitz
- @comp_bitz ||= collection.rand
+ def card
+ @card ||= collection.sample
end
def display
- comp_bitz.display
+ "#{card}"
end
def expected
- comp_bitz.expected
+ case mode
+ when :translate
+ card.translation
+ when :typing_practice
+ "#{card}"
+ else
+ raise "Invalid mode in Game Controller!"
+ end
end
def correct_msg
"#{I18n.t('Game.Correct')} #{input} = #{display}"
end
@@ -54,10 +63,10 @@
output << " #{I18n.t('Game.Its')} #{expected}" if mode == :translate
output
end
def valid?
- collection.correct?(input, comp_bitz)
+ !!(expected == input)
end
end
end
end
end