learn-japanese 0.8.0 → 0.9.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: b9551ba5848ab1baac33056aea1f97eaeba4057bf3de1c2cace4fe48b871e28d
4
- data.tar.gz: 4101529e9a6874489cc7001d5eccf4b83691cabdd0db6c057ce32fc92373c805
3
+ metadata.gz: c5c1fca5b0ff073f6ce6a77acf3bab9907a7375e0f9478ee7ce4c7ee36a3d52d
4
+ data.tar.gz: c06390a9a5be368f29e42520c152b3fafc9844363d2969ad989aaa1c5dc402f2
5
5
  SHA512:
6
- metadata.gz: 71d59ed075201be14f7f46d69e0d1ffe98d45f46c36b96cc62f56619198c00b8c35b22a398e414b60d789cc4ed475ddf3099ade875050f185e08bb324a99b917
7
- data.tar.gz: c81f8b3190ed01932c2f9483d87ebecdf9026df68c8b770631c735e89033ad6d2e89e3e30aa42b1144658beb30e1ef15ad071167592e2ad09c82e430131e80fa
6
+ metadata.gz: 3a886b203ddb9a0471c8e57341b34341b0d52c48e6134b4d96a8d03e8be44b1d226ae541729bd55fbdb23e09a29793366202f5f2d5505555d8368bae33f2cb63
7
+ data.tar.gz: 8d16c2416b30f85c75afe9e320b18ef0f4ac872c1acf675ae580df79a0fd78d47af5cce3e79946e19e9f1dfa0f0631266f7a6740af25c2f0069467c667aadbec
data/README.md CHANGED
@@ -5,9 +5,9 @@
5
5
 
6
6
  `learn-japanese` helps us to learn japanese.
7
7
 
8
- > WARNING: just only Hiragana (groups 1-4) for now.
9
-
10
- Every few week will be grow with more functions... at the same time I'm learning too... I hope.
8
+ > WARNING: just only Hiragana (groups 1-6) for now.
9
+ >
10
+ > Every few week will be grow with more functions... at the same time I'm learning too... I hope.
11
11
 
12
12
  ## Installation
13
13
 
@@ -16,15 +16,18 @@ Every few week will be grow with more functions... at the same time I'm learning
16
16
 
17
17
  ## Usage
18
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 |
19
+ * Open a terminal and run `learn-japanese` command to show available functions.
20
+
21
+ ```
22
+ ❯ ./bin/learn-japanese
23
+ Commands:
24
+ learn-japanese choose-answer [--level=NUMBER] # Values 1-6
25
+ learn-japanese help [COMMAND] # Describe available commands or one specific command
26
+ learn-japanese romaji # Write Romaji for Hiragana word
27
+ learn-japanese short-answer [--level=NUMBER] # Values 1-6
28
+ learn-japanese sound # Write sounds and get the Hiragana
29
+ learn-japanese version # Show the program version
30
+ ```
28
31
 
29
32
  # ANEXO
30
33
 
@@ -11,26 +11,30 @@ class CLI < Thor
11
11
  end
12
12
 
13
13
  map ['ca', '-ca', '--choose-answer', 'choose-answer'] => 'choose_answer'
14
- desc 'choose-answer [LEVEL]', 'LEVEL = 1-6'
15
- def choose_answer(level)
16
- LearnJapanese.choose_answer(level.to_i)
14
+ option :level
15
+ desc 'choose-answer [--level=NUMBER]', 'Values 1-6'
16
+ def choose_answer()
17
+ level = options[:level].to_i
18
+ LearnJapanese.choose_answer(level)
17
19
  end
18
20
 
19
21
  map ['sa', '-sa', '--short-answer', 'short-answer'] => 'short_answer'
20
- desc 'short-answer [LEVEL]', 'LEVEL = 1-6'
21
- def short_answer(level)
22
- LearnJapanese.short_answer(level.to_i)
22
+ option :level
23
+ desc 'short-answer [--level=NUMBER]', 'Values 1-6'
24
+ def short_answer()
25
+ level = options[:level].to_i
26
+ LearnJapanese.short_answer(level)
23
27
  end
24
28
 
25
29
  map ['so', '-so', '--sound', 'sound'] => 'sound'
26
- desc 'sound', 'Write sounds and get the Hiragana'
30
+ desc 'sound', 'Util: Write sounds and show Hiragana'
27
31
  def sound
28
32
  LearnJapanese.sound
29
33
  end
30
34
 
31
35
  map ['ro', '-ro', '--romanji' ] => 'romaji'
32
- desc 'romaji', 'Write Romaji for Hiragana word'
33
- def romanji
34
- LearnJapanese.romanji
36
+ desc 'romaji', 'You have to Write Romaji for every Hiragana word'
37
+ def romaji
38
+ LearnJapanese.romaji
35
39
  end
36
40
  end
@@ -1,93 +1,48 @@
1
+ require 'yaml'
1
2
  require 'colorize'
2
3
  require_relative '../debug'
3
4
 
4
- # Silabario japonés
5
5
  class Hiragana
6
+ # Silabario japonés
7
+ attr_reader :data
6
8
 
7
- def self.group1
8
- { a: "\u{3042}",
9
- i: "\u{3044}",
10
- u: "\u{3046}",
11
- e: "\u{3048}",
12
- o: "\u{304A}"
13
- }
9
+ def initialize
10
+ filename = File.join(File.dirname(__FILE__), 'hiragana.yaml')
11
+ @data = YAML.load(File.read(filename))
14
12
  end
15
13
 
16
- def self.group2
17
- { ka: "\u{304B}",
18
- ki: "\u{304D}",
19
- ku: "\u{304F}",
20
- ke: "\u{3051}",
21
- ko: "\u{3053}"
22
- }
14
+ def group(index)
15
+ @data[index - 1]
23
16
  end
24
17
 
25
- def self.group3
26
- { sa: "\u{3055}",
27
- shi: "\u{3057}",
28
- su: "\u{3059}",
29
- se: "\u{305B}",
30
- so: "\u{305D}"
31
- }
32
- end
33
-
34
- def self.group4
35
- { ta: "\u{305F}",
36
- chi: "\u{3061}",
37
- tsu: "\u{3064}", # つ
38
- te: "\u{3066}",
39
- to: "\u{3068}"
40
- }
41
- end
42
-
43
- def self.group5
44
- { na: "\u{306A}",
45
- ni: "\u{306B}",
46
- nu: "\u{306C}",
47
- ne: "\u{306D}",
48
- no: "\u{306E}"
49
- }
50
- end
51
-
52
- def self.group6
53
- { ha: "\u{306F}",
54
- hi: "\u{3072}",
55
- hu: "\u{3075}",
56
- he: "\u{3078}",
57
- ho: "\u{307B}"
58
- }
59
- end
60
-
61
- def self.all
62
- output = self.group1
63
- output.merge!(self.group2)
64
- output.merge!(self.group3)
65
- output.merge!(self.group4)
66
- output.merge!(self.group5)
67
- output.merge!(self.group6)
18
+ def all_groups
19
+ output = {}
20
+ @data.each do |group|
21
+ output.merge!(group)
22
+ end
68
23
  output
69
24
  end
70
25
 
71
- def self.groups(levels)
72
- return self.all if levels == :all
26
+ def groups(levels)
27
+ return all if levels == :all
73
28
  hiragana = {}
74
- hiragana.merge! Hiragana.group1 if levels.include? 1
75
- hiragana.merge! Hiragana.group2 if levels.include? 2
76
- hiragana.merge! Hiragana.group3 if levels.include? 3
77
- hiragana.merge! Hiragana.group4 if levels.include? 4
78
- hiragana.merge! Hiragana.group4 if levels.include? 5
79
- hiragana.merge! Hiragana.group4 if levels.include? 6
29
+ hiragana.merge! group 1 if levels.include? 1
30
+ hiragana.merge! group 2 if levels.include? 2
31
+ hiragana.merge! group 3 if levels.include? 3
32
+ hiragana.merge! group 4 if levels.include? 4
33
+ hiragana.merge! group 4 if levels.include? 5
34
+ hiragana.merge! group 5 if levels.include? 6
80
35
  hiragana
81
36
  end
82
37
 
83
- def self.sounds_to_hiragana(sounds)
84
- hiraganas = Hiragana.all
38
+ def sounds_to_hiragana(sounds)
39
+ hiraganas = all_groups
85
40
  hiragana_array = sounds.map { hiraganas[_1.to_sym] || '*' }
86
41
  hiragana = hiragana_array.join('')
87
42
  end
88
43
 
89
- def self.hiraganas_to_sound(hiraganas_input)
90
- all_hiraganas = Hiragana.all
44
+ def hiraganas_to_sound(hiraganas_input)
45
+ all_hiraganas = all_groups
91
46
 
92
47
  sounds_array = hiraganas_input.map do |hiragana_input|
93
48
  sound = '*'
@@ -100,16 +55,16 @@ class Hiragana
100
55
  sounds_array.join('')
101
56
  end
102
57
 
103
- def self.show_help(level=1)
58
+ def show_help(level=1)
104
59
  Debug.puts_line
105
60
  puts "Hiragana help\n".upcase.cyan
106
61
 
107
- Debug.puts_group Hiragana.group1
108
- Debug.puts_group Hiragana.group2 if level > 1
109
- Debug.puts_group Hiragana.group3 if level > 2
110
- Debug.puts_group Hiragana.group4 if level > 3
111
- Debug.puts_group Hiragana.group5 if level > 4
112
- Debug.puts_group Hiragana.group6 if level > 5
113
- Debug.puts_group Hiragana.group7 if level > 6
62
+ Debug.puts_group group(1)
63
+ Debug.puts_group group(2) if level > 1
64
+ Debug.puts_group group(3) if level > 2
65
+ Debug.puts_group group(4) if level > 3
66
+ Debug.puts_group group(5) if level > 4
67
+ Debug.puts_group group(6) if level > 5
68
+ Debug.puts_group group(7) if level > 6
114
69
  end
115
70
  end
@@ -0,0 +1,31 @@
1
+ ---
2
+ - :a: あ #"\u{3042}"
3
+ :i: い #"\u{3044}"
4
+ :u: う #"\u{3046}"
5
+ :e: え #"\u{3048}"
6
+ :o: お #"\u{304A}"
7
+ - :ka: か #"\u{304B}"
8
+ :ki: き #"\u{304D}"
9
+ :ku: く #"\u{304F}"
10
+ :ke: け #"\u{3051}"
11
+ :ko: こ #"\u{3053}"
12
+ - :sa: さ #"\u{3055}"
13
+ :shi: し #"\u{3057}"
14
+ :su: す #"\u{3059}"
15
+ :se: せ #"\u{305B}"
16
+ :so: そ #"\u{305D}"
17
+ - :ta: た #"\u{305F}"
18
+ :chi: ち #"\u{3061}"
19
+ :tsu: つ #"\u{3064}"
20
+ :te: て #"\u{3066}"
21
+ :to: と #"\u{3068}"
22
+ - :na: な #"\u{306A}"
23
+ :ni: に #"\u{306B#}"
24
+ :nu: ぬ #"\u{306C}"
25
+ :ne: ね #"\u{306D}"
26
+ :no: の #"\u{306E}"
27
+ - :ha: は #"\u{306F}"
28
+ :hi: ひ #"\u{3072}"
29
+ :hu: ふ #"\u{3075}"
30
+ :he: へ #"\u{3078}"
31
+ :ho: ほ #"\u{307B}"
@@ -6,6 +6,7 @@ require_relative '../data/hiragana'
6
6
  class ChooseAnswerGame
7
7
 
8
8
  def initialize(level=1, max=10)
9
+ @hiragana = Hiragana.new
9
10
  @level = level
10
11
  @score = 1
11
12
  @max_score = max
@@ -18,16 +19,13 @@ class ChooseAnswerGame
18
19
  #@silabario.merge! Hiragana.group5 if @level > 5
19
20
  #@silabario.merge! Hiragana.group6 if @level > 6
20
21
  levels = (1..@level).to_a
21
- @silabario = Hiragana.groups(levels)
22
+ @silabario = @hiragana.groups(levels)
22
23
 
23
24
  @keys = @silabario.keys
24
25
  end
25
26
 
26
- def self.show_help(level=1)
27
- Hiragana.show_help(level)
28
- end
29
-
30
27
  def run
28
+ @hiragana.show_help(@level)
31
29
  Debug.puts_line
32
30
  while @score < @max_score
33
31
  guess_japanise_symbol(@keys)
@@ -2,8 +2,9 @@
2
2
 
3
3
  require_relative '../debug'
4
4
  require_relative '../data/dictionary'
5
+ require_relative '../data/hiragana'
5
6
 
6
- class RomanjiGame
7
+ class RomajiGame
7
8
 
8
9
  def initialize(level=1, max=10)
9
10
  @level = level
@@ -17,13 +18,13 @@ class RomanjiGame
17
18
  Debug.puts_line
18
19
  while @score < @max_score
19
20
  @words.shuffle!
20
- guess_romanji(@words.first)
21
+ guess_romaji(@words.first)
21
22
  end
22
23
  end
23
24
 
24
25
  private
25
26
 
26
- def guess_romanji(data)
27
+ def guess_romaji(data)
27
28
  hiragana = data['hiragana']
28
29
  spanish = data['spanish']
29
30
  sounds = data['sounds']
@@ -33,14 +34,14 @@ class RomanjiGame
33
34
  resp = STDIN.gets.chomp
34
35
  exit if resp.empty?
35
36
 
36
- good = Hiragana.hiraganas_to_sound(hiragana.split(''))
37
+ good = Hiragana.new.hiraganas_to_sound(hiragana.split(''))
37
38
  if resp == good
38
39
  @score += 1
39
- puts ' '*10+"#{spanish} (#{sounds})".white
40
+ puts ' ' * 9 + "#{spanish} (#{sounds})".white
40
41
  return true
41
42
  end
42
43
  puts "Right answer is #{good}".light_red
43
- puts ' '*10+"#{spanish} (#{sounds})".red
44
+ puts ' ' * 9 + "#{spanish} (#{sounds})".red
44
45
  false
45
46
  end
46
47
 
@@ -6,25 +6,23 @@ require_relative '../data/hiragana'
6
6
  class ShortAnswerGame
7
7
 
8
8
  def initialize(level=1, max=10)
9
+ @hiragana = Hiragana.new
10
+
9
11
  @level = level
10
12
  @score = 1
11
13
  @max_score = max
12
14
 
13
- @silabario = Hiragana.group1
14
- @silabario.merge! Hiragana.group2 if @level > 1
15
- @silabario.merge! Hiragana.group3 if @level > 2
16
- @silabario.merge! Hiragana.group4 if @level > 3
17
- @silabario.merge! Hiragana.group5 if @level > 4
18
- @silabario.merge! Hiragana.group6 if @level > 5
15
+ @silabario = @hiragana.groups( (1..level).to_a )
19
16
 
20
17
  @keys = @silabario.keys
21
18
  end
22
19
 
23
- def self.show_help(level=1)
24
- Hiragana.show_help(level)
20
+ def show_help(level=1)
21
+ @hiragana.show_help(level)
25
22
  end
26
23
 
27
24
  def run
25
+ @hiragana.show_help(@level)
28
26
  Debug.puts_line
29
27
  while @score < @max_score
30
28
  @keys.shuffle!
@@ -4,10 +4,14 @@ require_relative '../debug'
4
4
  require_relative '../data/dictionary'
5
5
  require_relative '../data/hiragana'
6
6
 
7
- module SoundGame
7
+ class SoundGame
8
8
 
9
- def self.to_hiragana(sounds)
10
- hiragana = Hiragana.sounds_to_hiragana(sounds)
9
+ def initialize()
10
+ @hiragana = Hiragana.new
11
+ end
12
+
13
+ def to_hiragana(sounds)
14
+ hiragana = @hiragana.sounds_to_hiragana(sounds)
11
15
 
12
16
  none = {'hiragana' => hiragana, 'spanish' => '?', 'sounds' => '?'}
13
17
  words = Dictionary.words
@@ -16,7 +20,7 @@ module SoundGame
16
20
  word
17
21
  end
18
22
 
19
- def self.run
23
+ def run
20
24
  Debug.puts_line
21
25
  puts "SOUNDS TO HIRAGANA".light_cyan
22
26
  puts "Example: a i => あい (amor - ái)".blue
@@ -27,7 +31,7 @@ module SoundGame
27
31
  sounds = STDIN.gets.chomp.split
28
32
  return if sounds.empty?
29
33
 
30
- word = self.to_hiragana(sounds)
34
+ word = to_hiragana(sounds)
31
35
  print "Hiragana => ".white
32
36
  puts word["hiragana"]
33
37
  print "Spanish => ".white
@@ -1,6 +1,6 @@
1
1
 
2
2
  module LearnJapanese
3
- VERSION = '0.8.0'
3
+ VERSION = '0.9.0'
4
4
  NAME = 'learn-japanese'
5
5
  HOMEPAGE = 'https://github.com/dvarrui/learn-japanese'
6
6
  end
@@ -3,7 +3,7 @@ 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
5
  require_relative 'learn-japanese/game/sound-game'
6
- require_relative 'learn-japanese/game/romanji-game'
6
+ require_relative 'learn-japanese/game/romaji-game'
7
7
 
8
8
  module LearnJapanese
9
9
 
@@ -18,21 +18,20 @@ module LearnJapanese
18
18
 
19
19
  def self.choose_answer(level)
20
20
  show_help unless level > 0
21
- ChooseAnswerGame.show_help(level)
22
21
  ChooseAnswerGame.new(level).run
23
22
  end
24
23
 
24
+ def self.romaji
25
+ RomajiGame.new.run
26
+ end
27
+
25
28
  def self.short_answer(level)
26
29
  show_help unless level > 0
27
- ShortAnswerGame.show_help(level)
28
30
  ShortAnswerGame.new(level).run
29
31
  end
30
32
 
31
33
  def self.sound
32
- SoundGame.run
34
+ SoundGame.new.run
33
35
  end
34
36
 
35
- def self.romanji
36
- RomanjiGame.new.run
37
- end
38
37
  end
data/tests/all.rb ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative 'learn-japanese/data/hiragana_test'
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require_relative '../../../lib/learn-japanese/data/hiragana'
5
+
6
+ class HiraganaTest < Test::Unit::TestCase
7
+
8
+ def test_new
9
+ h = Hiragana.new
10
+
11
+ assert_equal 6, h.data.size
12
+ end
13
+
14
+ def test_every_group_has_6_symbols
15
+ data = Hiragana.new.data
16
+
17
+ data.each { |group| assert_equal 5, group.size }
18
+ end
19
+ 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.8.0
4
+ version: 0.9.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-05-12 00:00:00.000000000 Z
11
+ date: 2022-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -41,10 +41,7 @@ dependencies:
41
41
  description:
42
42
  email: dvarrui@protonmail.com
43
43
  executables:
44
- - choose-answer-game
45
44
  - learn-japanese
46
- - short-answer-game
47
- - sounds-to-hiragana
48
45
  extensions: []
49
46
  extra_rdoc_files: []
50
47
  files:
@@ -54,10 +51,7 @@ files:
54
51
  - LICENSE
55
52
  - README.md
56
53
  - Rakefile
57
- - bin/choose-answer-game
58
54
  - bin/learn-japanese
59
- - bin/short-answer-game
60
- - bin/sounds-to-hiragana
61
55
  - examples/01-emoji.rb
62
56
  - examples/02-emoji.rb
63
57
  - learn-japanese.gemspec
@@ -65,13 +59,16 @@ files:
65
59
  - lib/learn-japanese/cli.rb
66
60
  - lib/learn-japanese/data/dictionary.rb
67
61
  - lib/learn-japanese/data/hiragana.rb
62
+ - lib/learn-japanese/data/hiragana.yaml
68
63
  - lib/learn-japanese/data/words.yaml
69
64
  - lib/learn-japanese/debug.rb
70
65
  - lib/learn-japanese/game/choose-answer-game.rb
71
- - lib/learn-japanese/game/romanji-game.rb
66
+ - lib/learn-japanese/game/romaji-game.rb
72
67
  - lib/learn-japanese/game/short-answer-game.rb
73
68
  - lib/learn-japanese/game/sound-game.rb
74
69
  - lib/learn-japanese/version.rb
70
+ - tests/all.rb
71
+ - tests/learn-japanese/data/hiragana_test.rb
75
72
  homepage: https://github.com/dvarrui/learn-japanese
76
73
  licenses:
77
74
  - GPL-3
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
- require 'learn-japanese/game/choose-answer-game'
5
-
6
- def get_level
7
- level = ARGV.first.to_i
8
-
9
- if level.zero?
10
- name = File.basename(__FILE__)
11
- puts "Usage: #{name} [LEVEL] # LEVEL is [1,2,3,4]"
12
- exit 0
13
- end
14
- level
15
- end
16
-
17
- level = get_level
18
- ChooseAnswerGame.show_help(level)
19
- ChooseAnswerGame.new(level).run
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
- require 'learn-japanese/game/short-answer-game'
5
-
6
- def get_level
7
- level = ARGV.first.to_i
8
-
9
- if level.zero?
10
- name = File.basename(__FILE__)
11
- puts "Usage: #{name} [LEVEL] # LEVEL is [1,2,3,4]"
12
- exit 0
13
- end
14
- level
15
- end
16
-
17
- level = get_level
18
- ShortAnswerGame.show_help(level)
19
- ShortAnswerGame.new(level).run
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
- require 'learn-japanese/game/sound-game'
5
-
6
- SoundGame.run