class Sycontact::AddressBook
AddressBook
is a wrapper for source modules that contain a script for retrieving contact data from a source as Internet, LDAP server or a file
Constants
- SUMMARY
Holds the values that are used when printing the summary of a contact
Public Class Methods
new(source)
click to toggle source
Creates a new AddressBook
. It requires the source module file and extends AddressBook
with the source module
# File lib/sycontact/address_book.rb, line 13 def initialize(source) source = source.sub('.rb', '') require source @module_name = pascalize(File.basename(source)) extend self.class.module_eval(@module_name) end
Public Instance Methods
method_missing(method, *args) { |k, v| ... }
click to toggle source
The source module can override the address source title, print_summary and print_all methods. If the methods are not overridden the default methods are invoked. The source module has to provide a lookup method. If the lookup method is not available “method missing” will be thrown
Calls superclass method
# File lib/sycontact/address_book.rb, line 24 def method_missing(method, *args, &block) case method when :title @module_name when :print_summary args.each do |contact| puts "\n" contact.each do |k,v| if block_given? yield(k, v) else unless SUMMARY.index(k).nil? puts "#{k.to_s.upcase.ljust(20, '.')}#{v}\n" unless v.nil? or v.empty? end end end end when :print_all args.each do |contact| puts "\n" contact.each do |k,v| if block_given? yield(k, v) else puts "#{k.to_s.upcase.ljust(20, '.')}#{v}\n" unless v.nil? or v.empty? end end end else super end end
Private Instance Methods
pascalize(string)
click to toggle source
Pascalizes/camalizes a string as address_source to AddressSource
# File lib/sycontact/address_book.rb, line 60 def pascalize(string) (string.split('_').map { |word| word.capitalize }).join end