3 require './addressbook_pb'
6 # Iterates though all people in the AddressBook and prints info about them.
7 def list_people(address_book)
8 address_book.people.each do |person|
9 puts "Person ID: #{person.id}"
10 puts " Name: #{person.name}"
12 puts " Email: #{person.email}"
15 person.phones.each do |phone_number|
17 case phone_number.type
25 puts " #{type} #: #{phone_number.number}"
30 # Main procedure: Reads the entire address book from a file and prints all
31 # the information inside.
33 puts "Usage: #{$PROGRAM_NAME} ADDRESS_BOOK_FILE"
37 # Read the existing address book.
38 f = File.open(ARGV[0], "rb")
39 address_book = Tutorial::AddressBook.decode(f.read)
42 list_people(address_book)