-
Notifications
You must be signed in to change notification settings - Fork 0
/
conjugator.rb
94 lines (77 loc) · 2.24 KB
/
conjugator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# frozen_string_literal: true
require_relative 'lib/name'
require_relative 'lib/i_adjective'
require_relative 'lib/na_adjective'
require_relative 'lib/ichidan_verb'
require_relative 'lib/godan_verb'
require_relative 'lib/irregular_verb'
module Constants
VERSION = '5.0'
MENU_OPTIONS = {
'Nouns (名詞).' => Name,
'Group 1/る Verbs (一段活用).' => IchidanVerb,
'Group 2/う Verbs (五段活用).' => GodanVerb,
'Group 3/Irregular Verbs (変な活用).' => IrregularVerb,
'な Adjectives (形容動詞).' => NaAdjective,
'い Adjectives (形容詞).' => IAdjective,
'Irregular) い Adjectives (変な形容詞).' => IAdjective,
'Exit' => nil
}.freeze
end
class Conjugator
def initialize
@words = []
end
def add_word(word)
@words << word
end
def conjugate_all
@words.each do |word|
conjugations = word.conjugate
conjugations.each do |form, value|
puts "#{form}: #{value}"
end
end
end
end
def ask_conjugate_another_word?
loop do
print 'Do you want to conjugate another word? (y/n): '
choice = gets.chomp.downcase
return true if choice == 'y'
return false if choice == 'n'
puts "Invalid choice. Please enter 'y' for yes or 'n' for no."
end
end
def display_menu
puts(" 活ヨウ - KatsuYou - a CLI by Leonardo Quadros Fragozo #{Constants::VERSION}")
puts("\n")
puts(' What do you want to conjugate? - Type the number to select the option.')
puts("\n")
Constants::MENU_OPTIONS.each_with_index do |(option, _), index|
puts("#{index + 1} - #{option}")
end
end
def get_user_input(prompt)
print(prompt)
gets.chomp
end
conjugator = Conjugator.new
loop do
display_menu
print("Enter your choice (1-#{Constants::MENU_OPTIONS.size}): ")
choice = gets.chomp.to_i
if choice.between?(1, Constants::MENU_OPTIONS.size - 1)
selected_option = Constants::MENU_OPTIONS.to_a[choice - 1]
word_class = selected_option[1]
print('Enter the word: ')
word = gets.chomp
word_object = word_class.new(word)
conjugator.add_word(word_object)
conjugator.conjugate_all
break unless ask_conjugate_another_word?
else
puts("Invalid option. Please select a valid option (1-#{Constants::MENU_OPTIONS.size - 1}).")
end
puts
end