Class: Hiragana

Inherits:
Object
  • Object
show all
Defined in:
lib/learn-japanese/data/hiragana.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHiragana

Returns a new instance of Hiragana.



9
10
11
12
# File 'lib/learn-japanese/data/hiragana.rb', line 9

def initialize
  filename = File.join(File.dirname(__FILE__), 'hiragana.yaml')
  @data = YAML.load(File.read(filename))
end

Instance Attribute Details

#dataObject (readonly)

Silabario japonés



7
8
9
# File 'lib/learn-japanese/data/hiragana.rb', line 7

def data
  @data
end

Instance Method Details

#all_groupsObject



18
19
20
21
22
23
24
# File 'lib/learn-japanese/data/hiragana.rb', line 18

def all_groups
  output = {}
  @data.each do |group|
    output.merge!(group)
  end
  output
end

#group(index) ⇒ Object



14
15
16
# File 'lib/learn-japanese/data/hiragana.rb', line 14

def group(index)
  @data[index - 1]
end

#groups(levels) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/learn-japanese/data/hiragana.rb', line 26

def groups(levels)
  return all if levels == :all
  hiragana = {}
  hiragana.merge! group 1 if levels.include? 1
  hiragana.merge! group 2 if levels.include? 2
  hiragana.merge! group 3 if levels.include? 3
  hiragana.merge! group 4 if levels.include? 4
  hiragana.merge! group 4 if levels.include? 5
  hiragana.merge! group 5 if levels.include? 6
  hiragana
end

#hiraganas_to_sound(hiraganas_input) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/learn-japanese/data/hiragana.rb', line 44

def hiraganas_to_sound(hiraganas_input)
  all_hiraganas = all_groups

  sounds_array = hiraganas_input.map do |hiragana_input|
    sound = '*'
    all_hiraganas.each_pair do |key, value|
      sound = key if value == hiragana_input
    end
    sound
  end

  sounds_array.join('')
end

#show_help(level = 1) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/learn-japanese/data/hiragana.rb', line 58

def show_help(level=1)
  Debug.puts_line
  puts "Hiragana help\n".upcase.cyan

  Debug.puts_group group(1)
  Debug.puts_group group(2) if level > 1
  Debug.puts_group group(3) if level > 2
  Debug.puts_group group(4) if level > 3
  Debug.puts_group group(5) if level > 4
  Debug.puts_group group(6) if level > 5
  Debug.puts_group group(7) if level > 6
end

#sounds_to_hiragana(sounds) ⇒ Object



38
39
40
41
42
# File 'lib/learn-japanese/data/hiragana.rb', line 38

def sounds_to_hiragana(sounds)
  hiraganas = all_groups
  hiragana_array = sounds.map { hiraganas[_1.to_sym] || '*' }
  hiragana = hiragana_array.join('')
end