-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcards.rb
More file actions
49 lines (44 loc) · 1022 Bytes
/
cards.rb
File metadata and controls
49 lines (44 loc) · 1022 Bytes
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
require_relative "card"
CARDS_FILE = "cards.txt"
WRITE_CARD_OPTION = 1
puts "Bem vindo ao Cards System!"
continuar = ""
while continuar != "N"
puts ""
puts "[1] escrever\n[2] Ver um card"
puts "[3] Encontrar"
puts "Entre com a opção:"
opcao = gets.to_i
if opcao == WRITE_CARD_OPTION
print 'Portugues: '
portugues = gets.chomp
print 'Ingles: '
ingles = gets.chomp
card = Card.new(portugues, ingles)
File.open(CARDS_FILE, "a") do |f|
f.puts card.to_write
end
puts card
elsif opcao == 2
cards = Card.all
unless cards.empty?
puts cards.sample
else
"Nenhum card cadastrado!"
end
elsif opcao == 3
print "Texto: "
texto_procurar = gets.chomp
cards = Card.where(texto_procurar)
if cards.any?
puts "Encontrado #{cards.size} card(s)"
cards.each { |card| puts card }
end
else
puts "Opção inválida!"
end
puts "Deseja continuar?"
puts "[S] Sim"
puts "[N] Não"
continuar = gets.chomp.upcase
end