learn-japanese 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c326b07ac2656bdfcaf385898b70c589d8fa7571bf6adbcb4b7b369130dd51d5
4
- data.tar.gz: 1c19e75e31d96b4d3b9e11d349c8c24f0e2f0b71649193afe73f4cb02c192a04
3
+ metadata.gz: 164745bdc76d66bff134ec0e06fb5fceef44fb480f9c266c32beb6342dfe252b
4
+ data.tar.gz: 9bea86b40b59102cad35e1749fc379e6c14b2384b9f6f6f4b0abcd29409c446b
5
5
  SHA512:
6
- metadata.gz: 7e06b77a12fabb4667ecba8a4c681b7e1e4e6c3616d8c7ecfebc63da7cb7e21c1da8a2fade41a35d95549e9951276eca99ef358fc1e39156856eb663cacd688e
7
- data.tar.gz: e67a8f0828e1d1683d085e6ab6ebabf8af0882a2524d9f3e84442f06d10e0407b00e86d97dfbcdbe0c9e70b3a899749f735d35ae0ecc65dccbfa876b3082e32d
6
+ metadata.gz: a0b5cf252d1a7eefb8b3953a7285bb7a6ec99b1059c284f7f934ca7813307ba37f9297423a77498277750b1a6da17745bb1c200f7067607a45884c70edb9bb17
7
+ data.tar.gz: 37b4068955aa70702a166265a2e9482e9141da5404251f0888a1f2bce44337b9970f70edafd0adc5cf81d20574d2431533e795a9e158ca737d5f440645b7dec8
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.0
data/README.md CHANGED
@@ -1,25 +1,32 @@
1
1
 
2
2
  [![Gem Version](https://badge.fury.io/rb/learn-japanese.svg)](https://badge.fury.io/rb/learn-japanese)
3
3
 
4
- # Aprender japonés
4
+ # Learn Japanese
5
5
 
6
- `learn-japanese` es un programa Ruby de licencia libre para ayudar a aprender el japonés.
7
- De momento, sólo se está empezando a implementar la funcionalidad para aprender el Silabario Hiragana, pero poco a poco irá creciendo a medida que yo mismo aprenda más japonés.
6
+ `learn-japanese` helps us to learn japanese.
8
7
 
9
- Para instalar el programa:
10
- 1. Debes tener Ruby instalado en tu equipo.
11
- 2. Abrir un terminal y ejecutar `sudo gem install learn-japanese`, para instalar la herramienta.
8
+ > WARNING: just only Hiragana (groups 1-4) for now.
12
9
 
13
- ## Modo de Uso
10
+ Every few week will be grow with more functions... at the same time I'm learning too... I hope.
14
11
 
15
- Abrir un terminal
16
- * Ejecutar `short-answer-game`, para el juego de preguntas donde debemos escribir la respuesta.
17
- * Ejecutar `choose-answer-game`, para el juego de preguntas donde debemos elegir la respuesta correcta.
18
- * `sounds-to-hiragana`, pasar sonidos a Hiragana.
12
+ ## Installation
19
13
 
20
- > NOTA: Para aumentar la dificultad haremos `short-answer-game NUMBER`, donde NUMBER será un valor entre 1-4 por el momento.
14
+ 1. Install Ruby on your system.
15
+ 2. Open a terminal and run `sudo gem install learn-japanese`, to install the Ruby gem.
21
16
 
22
- # Silabario japonés
17
+ ## Usage
18
+
19
+ * Open a terminal and run `learn-japanese`.
20
+
21
+ ## Functions or mini-games
22
+
23
+ | Function name | Description |
24
+ | ------------- | ---------------------------------------- |
25
+ | short-answer | Write the sound associated to the symbol |
26
+ | choose-answer | Choose the symbol associated to the sound |
27
+ | sound | Write the sounds and get the word |
28
+
29
+ # ANEXO
23
30
 
24
31
  ## Hiragana
25
32
 
@@ -3,4 +3,4 @@
3
3
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
4
  require 'learn-japanese/game/sound-game'
5
5
 
6
- SoundGame.loop_hiragana_game
6
+ SoundGame.run
@@ -21,4 +21,16 @@ class CLI < Thor
21
21
  def short_answer(level)
22
22
  LearnJapanese.short_answer(level.to_i)
23
23
  end
24
+
25
+ map ['so', '-so', '--sound', 'sound'] => 'sound'
26
+ desc 'sound', 'Write sounds and get the Hiragana'
27
+ def sound
28
+ LearnJapanese.sound
29
+ end
30
+
31
+ map ['ro', '-ro', '--romanji' ] => 'romaji'
32
+ desc 'romaji', 'Write Romaji for Hiragana word'
33
+ def romanji
34
+ LearnJapanese.romanji
35
+ end
24
36
  end
@@ -0,0 +1,11 @@
1
+
2
+ require 'yaml'
3
+
4
+ module Dictionary
5
+
6
+ def self.words
7
+ filename = File.join(File.dirname(__FILE__), 'words.yaml')
8
+ words = YAML.load(File.read(filename))
9
+ end
10
+
11
+ end
@@ -1,5 +1,5 @@
1
1
  require 'colorize'
2
- require_relative 'debug'
2
+ require_relative '../debug'
3
3
 
4
4
  # Silabario japonés
5
5
  class Hiragana
@@ -24,7 +24,7 @@ class Hiragana
24
24
 
25
25
  def self.group3
26
26
  { sa: "\u{3055}",
27
- si: "\u{3057}",
27
+ shi: "\u{3057}",
28
28
  su: "\u{3059}",
29
29
  se: "\u{305B}",
30
30
  so: "\u{305D}"
@@ -33,8 +33,8 @@ class Hiragana
33
33
 
34
34
  def self.group4
35
35
  { ta: "\u{305F}",
36
- ti: "\u{3061}",
37
- tu: "\u{3064}",
36
+ chi: "\u{3061}",
37
+ tsu: "\u{3064}",
38
38
  te: "\u{3066}",
39
39
  to: "\u{3068}"
40
40
  }
@@ -48,6 +48,36 @@ class Hiragana
48
48
  output
49
49
  end
50
50
 
51
+ def self.groups(levels)
52
+ return self.all if levels == :all
53
+ hiragana = {}
54
+ hiragana.merge! Hiragana.group1 if levels.include? 1
55
+ hiragana.merge! Hiragana.group2 if levels.include? 2
56
+ hiragana.merge! Hiragana.group3 if levels.include? 3
57
+ hiragana.merge! Hiragana.group4 if levels.include? 4
58
+ hiragana
59
+ end
60
+
61
+ def self.sounds_to_hiragana(sounds)
62
+ hiraganas = Hiragana.all
63
+ hiragana_array = sounds.map { hiraganas[_1.to_sym] || '*' }
64
+ hiragana = hiragana_array.join('')
65
+ end
66
+
67
+ def self.hiraganas_to_sound(hiraganas_input)
68
+ all_hiraganas = Hiragana.all
69
+
70
+ sounds_array = hiraganas_input.map do |hiragana_input|
71
+ sound = '*'
72
+ all_hiraganas.each_pair do |key, value|
73
+ sound = key if value == hiragana_input
74
+ end
75
+ sound
76
+ end
77
+
78
+ sounds_array.join('')
79
+ end
80
+
51
81
  def self.show_help(level=1)
52
82
  Debug.puts_line
53
83
  puts "Hiragana help\n".upcase.cyan
@@ -1,19 +1,49 @@
1
1
  ---
2
- - sounds: e
3
- hiragana: え
4
- spanish: pintura
5
2
  - sounds: ái
6
3
  hiragana: あい
7
4
  spanish: amor
5
+ - sounds: áka
6
+ hiragana: あか
7
+ spanish: rojo
8
8
  - sounds: áo
9
9
  hiragana: あお
10
10
  spanish: azul
11
+ - sounds: e
12
+ hiragana: え
13
+ spanish: pintura
14
+ - sounds: éki
15
+ hiragana: えき
16
+ spanish: estación de tren
11
17
  - sounds: ié
12
18
  hiragana: いえ
13
19
  spanish: casa
14
20
  - sounds: íi
15
21
  hiragana: いい
16
22
  spanish: bien
23
+ - sounds: i-e
24
+ hiragana: いいえ
25
+ spanish: 'no'
17
26
  - sounds: ué
18
27
  hiragana: うえ
19
28
  spanish: arriba
29
+ - sounds: ka
30
+ hiragana: か
31
+ spanish: mosquito
32
+ - sounds: kaó
33
+ hiragana: かお
34
+ spanish: cara
35
+ - sounds: ki
36
+ hiragana: き
37
+ spanish: árbol
38
+ - sounds: kíkai
39
+ hiragana: きかい
40
+ spanish: máquina, oportunidad
41
+ - sounds: áisatsu
42
+ hiragana: あいさつ
43
+ spanish: salud
44
+ - sounds: áisatsu wo suru
45
+ hiragana: あいさつをする
46
+ spanish: saludar
47
+ - sounds: ohayou
48
+ hiragana: おはよう
49
+ spanish: Buenos días (casual)
@@ -15,4 +15,9 @@ class Debug
15
15
  def self.puts_line
16
16
  STDOUT.puts ('=' * 20).white
17
17
  end
18
+
19
+ def self.break
20
+ require 'debug'
21
+ binding.break
22
+ end
18
23
  end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../debug'
4
- require_relative '../hiragana'
4
+ require_relative '../data/hiragana'
5
5
 
6
6
  class ChooseAnswerGame
7
7
 
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../debug'
4
+ require_relative '../data/dictionary'
5
+
6
+ class RomanjiGame
7
+
8
+ def initialize(level=1, max=10)
9
+ @level = level
10
+ @score = 1
11
+ @max_score = max
12
+
13
+ @words = Dictionary.words
14
+ end
15
+
16
+ def run
17
+ Debug.puts_line
18
+ while @score < @max_score
19
+ @words.shuffle!
20
+ guess_romanji(@words.first)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def guess_romanji(data)
27
+ hiragana = data['hiragana']
28
+ spanish = data['spanish']
29
+ sounds = data['sounds']
30
+ progress = "[ #{@score}/#{@max_score} ]"
31
+
32
+ print "#{progress.white} Write Romanji for #{hiragana.light_yellow}: "
33
+ resp = STDIN.gets.chomp
34
+ exit if resp.empty?
35
+
36
+ good = Hiragana.hiraganas_to_sound(hiragana.split(''))
37
+ if resp == good
38
+ @score += 1
39
+ puts ' '*10+"#{spanish} (#{sounds})".white
40
+ return true
41
+ end
42
+ puts "Right answer is #{good}".light_red
43
+ puts ' '*10+"#{spanish} (#{sounds})".red
44
+ false
45
+ end
46
+
47
+ end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../debug'
4
- require_relative '../hiragana'
4
+ require_relative '../data/hiragana'
5
5
 
6
6
  class ShortAnswerGame
7
7
 
@@ -1,33 +1,39 @@
1
1
 
2
- require_relative '../hiragana'
3
- require_relative '../dictionary'
4
2
  require 'colorize'
3
+ require_relative '../debug'
4
+ require_relative '../data/dictionary'
5
+ require_relative '../data/hiragana'
5
6
 
6
7
  module SoundGame
7
8
 
8
9
  def self.to_hiragana(sounds)
9
- hiraganas = Hiragana.all
10
+ hiragana = Hiragana.sounds_to_hiragana(sounds)
10
11
 
11
- hiragana_array = sounds.map { hiraganas[_1.to_sym] || '*' }
12
- hiragana = hiragana_array.join('')
13
-
14
- none = {'hiragana': hiragana, 'spanish': '?', 'sounds': '?'}
15
- words = Dictionary.new.words
12
+ none = {'hiragana' => hiragana, 'spanish' => '?', 'sounds' => '?'}
13
+ words = Dictionary.words
16
14
  word = (words.select {_1["hiragana"] == hiragana})[0] || none
17
15
 
18
16
  word
19
17
  end
20
18
 
21
- def self.loop_hiragana_game
22
- sounds = "init"
23
- until sounds.empty?
24
- puts "[ Sounds to Hiragana ] Example: a i => あい (amor - ái)".white
25
- print " Write sounds ? ".light_yellow
26
- sounds = gets.chomp.split
19
+ def self.run
20
+ Debug.puts_line
21
+ puts "SOUNDS TO HIRAGANA".light_cyan
22
+ puts "Example: a i => あい (amor - ái)".blue
23
+ Debug.puts_line
24
+
25
+ loop do
26
+ print "\nWrite sounds ? ".light_yellow
27
+ sounds = STDIN.gets.chomp.split
28
+ return if sounds.empty?
29
+
27
30
  word = self.to_hiragana(sounds)
28
- puts " Hiragana => #{word["hiragana"]}".cyan
29
- puts " Spanish => #{word["spanish"]}".cyan
30
- puts " Pronounce => #{word["sounds"]}".cyan
31
+ print "Hiragana => ".white
32
+ puts word["hiragana"]
33
+ print "Spanish => ".white
34
+ puts word["spanish"]
35
+ print "Pronounce => ".white
36
+ puts word["sounds"]
31
37
  end
32
38
  end
33
39
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  module LearnJapanese
3
- VERSION = '0.5.0'
3
+ VERSION = '0.7.0'
4
4
  NAME = 'learn-japanese'
5
5
  HOMEPAGE = 'https://github.com/dvarrui/learn-japanese'
6
6
  end
@@ -2,6 +2,8 @@
2
2
  require_relative 'learn-japanese/version'
3
3
  require_relative 'learn-japanese/game/choose-answer-game'
4
4
  require_relative 'learn-japanese/game/short-answer-game'
5
+ require_relative 'learn-japanese/game/sound-game'
6
+ require_relative 'learn-japanese/game/romanji-game'
5
7
 
6
8
  module LearnJapanese
7
9
 
@@ -25,4 +27,12 @@ module LearnJapanese
25
27
  ShortAnswerGame.show_help(level)
26
28
  ShortAnswerGame.new(level).run
27
29
  end
30
+
31
+ def self.sound
32
+ SoundGame.run
33
+ end
34
+
35
+ def self.romanji
36
+ RomanjiGame.new.run
37
+ end
28
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: learn-japanese
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Vargas Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-18 00:00:00.000000000 Z
11
+ date: 2022-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -49,6 +49,7 @@ extensions: []
49
49
  extra_rdoc_files: []
50
50
  files:
51
51
  - ".gitignore"
52
+ - ".ruby-version"
52
53
  - Gemfile
53
54
  - LICENSE
54
55
  - README.md
@@ -62,13 +63,14 @@ files:
62
63
  - learn-japanese.gemspec
63
64
  - lib/learn-japanese.rb
64
65
  - lib/learn-japanese/cli.rb
66
+ - lib/learn-japanese/data/dictionary.rb
67
+ - lib/learn-japanese/data/hiragana.rb
65
68
  - lib/learn-japanese/data/words.yaml
66
69
  - lib/learn-japanese/debug.rb
67
- - lib/learn-japanese/dictionary.rb
68
70
  - lib/learn-japanese/game/choose-answer-game.rb
71
+ - lib/learn-japanese/game/romanji-game.rb
69
72
  - lib/learn-japanese/game/short-answer-game.rb
70
73
  - lib/learn-japanese/game/sound-game.rb
71
- - lib/learn-japanese/hiragana.rb
72
74
  - lib/learn-japanese/version.rb
73
75
  homepage: https://github.com/dvarrui/learn-japanese
74
76
  licenses:
@@ -1,12 +0,0 @@
1
-
2
- require 'yaml'
3
-
4
- class Dictionary
5
- attr_reader :words
6
-
7
- def initialize()
8
- filename = File.join(File.dirname(__FILE__), 'data', 'words.yaml')
9
- @words = YAML.load(File.read(filename))
10
- end
11
-
12
- end