Class: SoundGame

Inherits:
Object
  • Object
show all
Defined in:
lib/learn-japanese/game/sound-game.rb

Instance Method Summary collapse

Constructor Details

#initializeSoundGame

Returns a new instance of SoundGame.



9
10
11
# File 'lib/learn-japanese/game/sound-game.rb', line 9

def initialize()
  @hiragana = Hiragana.new
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/learn-japanese/game/sound-game.rb', line 23

def run
  Debug.puts_line
  puts "SOUNDS TO HIRAGANA".light_cyan
  puts "Example: a i => あい (amor - ái)".blue
  Debug.puts_line

  loop do
    print "\nWrite sounds ? ".light_yellow
    sounds = STDIN.gets.chomp.split
    return if sounds.empty?

    word = to_hiragana(sounds)
    print "Hiragana    => ".white
    puts word["hiragana"]
    print "Spanish     => ".white
    puts word["spanish"]
    print "Pronounce   => ".white
    puts word["sounds"]
  end
end

#to_hiragana(sounds) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/learn-japanese/game/sound-game.rb', line 13

def to_hiragana(sounds)
  hiragana = @hiragana.sounds_to_hiragana(sounds)

  none = {'hiragana' => hiragana, 'spanish' => '?', 'sounds' => '?'}
  words = Dictionary.words
  word = (words.select {_1["hiragana"] == hiragana})[0] || none

  word
end