forked from maximiliano/Curso-Ruby-Rails-da-Tink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagenda.rb
47 lines (42 loc) · 1.18 KB
/
agenda.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
class Agenda
def initialize
puts "Agenda criada"
end
def cadastrar
puts "Digite os dados da pessoa:"
puts "Nome: " ; nome = gets.chomp
puts "- Dados para contato -"
puts "Telefone fixo" ; fixo = gets.chomp
puts "Telefone celular" ; celular = gets.chomp
puts "Telefone ramal" ; ramal = gets.chomp
puts "- Dados residenciais - "
puts "Rua" ; rua = gets.chomp
puts "Bairro" ; bairro = gets.chomp
puts "Numero" ; numero = gets.chomp
puts "Sala" ; sala = gets.chomp
puts "Complemento" ; complemento = gets.chomp
Contato.new({"Nome" => nome}, Telefone.new(celular, fixo, ramal), Endereco.new(rua, bairro, numero, sala, complemento))
end
def consultar
File.open("teste.yml") do |txt|
YAML::load_documents( txt ) do |objs|
objs.each do |k, v|
puts "#{k}: #{v}" unless v.empty?
end
puts
end
end
end
def buscar(tipo, buscado)
File.open("teste.yml") do |txt|
YAML::load_documents( txt ) do |objs|
if objs[tipo] =~ /#{buscado}/i
objs.each do |k, v|
puts "#{k}: #{v}" unless v.empty?
end
end
puts
end
end
end
end