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