class LanguageCards::Controllers::Game
Public Instance Methods
card()
click to toggle source
# File lib/language_cards/controllers/game.rb, line 35 def card @card ||= card_set.sample.current end
correct_msg()
click to toggle source
# File lib/language_cards/controllers/game.rb, line 54 def correct_msg "#{I18n.t('Game.Correct')} #{input} = #{display}" end
display()
click to toggle source
# File lib/language_cards/controllers/game.rb, line 39 def display "#{card}" end
expected()
click to toggle source
# File lib/language_cards/controllers/game.rb, line 43 def expected case mode when :translate card.translation when :typing_practice "#{card}" else raise "Invalid mode in Game Controller!" end end
get_input()
click to toggle source
# File lib/language_cards/controllers/game.rb, line 31 def get_input @input ||= CLI.ask("#{I18n.t('Game.TypeThis')}: #{display}") end
incorrect_msg()
click to toggle source
# File lib/language_cards/controllers/game.rb, line 58 def incorrect_msg output = "#{I18n.t('Game.Incorrect')} #{input} != #{display}" output << " #{I18n.t('Game.Its')} #{expected.join(', ')}" if mode == :translate output end
input()
click to toggle source
# File lib/language_cards/controllers/game.rb, line 27 def input @input end
process(cards, mode)
click to toggle source
# File lib/language_cards/controllers/game.rb, line 16 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 } end
render(correct:, incorrect:, title:, timer:, last:)
click to toggle source
Calls superclass method
LanguageCards::Controllers::ApplicationController#render
# File lib/language_cards/controllers/game.rb, line 8 def render(correct:, incorrect:, title:, timer:, last:) _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' super(binding) end
struct_data()
click to toggle source
# File lib/language_cards/controllers/game.rb, line 25 def struct_data Struct.new(:card_set, :mode) do def input @input end def get_input @input ||= CLI.ask("#{I18n.t('Game.TypeThis')}: #{display}") end def card @card ||= card_set.sample.current end def display "#{card}" end def 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 def incorrect_msg output = "#{I18n.t('Game.Incorrect')} #{input} != #{display}" output << " #{I18n.t('Game.Its')} #{expected.join(', ')}" if mode == :translate output end def valid? card_set.match? input end end end
valid?()
click to toggle source
# File lib/language_cards/controllers/game.rb, line 64 def valid? card_set.match? input end