Module: SoundGame
- Defined in:
- lib/learn-japanese/game/sound-game.rb
Class Method Summary collapse
Class Method Details
.loop_hiragana_game ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/learn-japanese/game/sound-game.rb', line 21 def self.loop_hiragana_game sounds = "init" until sounds.empty? puts "[ Sounds to Hiragana ] Example: a i => あい (amor - ái)".white print " Write sounds ? ".light_yellow sounds = gets.chomp.split word = self.to_hiragana(sounds) puts " Hiragana => #{word["hiragana"]}".cyan puts " Spanish => #{word["spanish"]}".cyan puts " Pronounce => #{word["sounds"]}".cyan end end |
.to_hiragana(sounds) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/learn-japanese/game/sound-game.rb', line 8 def self.to_hiragana(sounds) hiraganas = Hiragana.all hiragana_array = sounds.map { hiraganas[_1.to_sym] || '*' } hiragana = hiragana_array.join('') none = {'hiragana': hiragana, 'spanish': '?', 'sounds': '?'} words = Dictionary.new.words word = (words.select {_1["hiragana"] == hiragana})[0] || none word end |