class Sycontact::AddressBookLibrary
AddressBookLibrary
creates AddressBook
objects and forwards all messages invoked on AddressBookLibrary
to all AddressBooks.
Attributes
contacts[R]
The contacts from the last lookup invocation
Public Class Methods
new(address_book_directory)
click to toggle source
Creates AddressBook
objects based on the address book source files contained in the address_book_directory
# File lib/sycontact/address_book_library.rb, line 15 def initialize(address_book_directory) @address_books = [] Dir.glob(File.join(address_book_directory, "*_source.rb")).each do |address_book| @address_books << AddressBook.new(address_book) end end
Public Instance Methods
lookup(pattern = {})
click to toggle source
Looks up a contact based on the pattern and returns the contact data as a hash. The contact data can subsequentially retrievied with :contacts
# File lib/sycontact/address_book_library.rb, line 24 def lookup(pattern = {}) @contacts = {} @address_books.each do |address_book| puts "\n#{address_book.title}\n" @contacts[address_book.title] = address_book.lookup(pattern) end @contacts end
print_all(pattern = {})
click to toggle source
Invokes a lookup on all AddressBook
objects and prints the result to the console with all attributes found in the contact source
# File lib/sycontact/address_book_library.rb, line 35 def print_all(pattern = {}) @address_books.each do |address_book| puts "\n#{address_book.title}" address_book.lookup(pattern).each do |contact| address_book.print_all(contact) end end end
print_summary(pattern = {})
click to toggle source
Invokes a lookup on all AddressBook
objects and prints a subset of the result to the console. The attributes that are selected for print are defined in AddressBook::SUMMARY
# File lib/sycontact/address_book_library.rb, line 46 def print_summary(pattern = {}) @address_books.each do |address_book| puts "\n#{address_book.title}" address_book.lookup(pattern).each do |contact| address_book.print_summary(contact) end end end