2011-03-07 21:38:20 +00:00
|
|
|
require 'avm/contact'
|
|
|
|
|
2011-03-07 17:39:47 +00:00
|
|
|
module AVM
|
|
|
|
class Creator
|
2011-03-07 21:38:20 +00:00
|
|
|
attr_reader :contacts
|
|
|
|
|
2011-03-07 17:39:47 +00:00
|
|
|
def initialize
|
|
|
|
@options = {}
|
2011-03-07 21:38:20 +00:00
|
|
|
@contacts = []
|
2011-03-07 17:39:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def merge!(hash)
|
|
|
|
@options.merge!(hash)
|
|
|
|
end
|
|
|
|
|
2011-03-07 21:38:20 +00:00
|
|
|
def address
|
|
|
|
primary_contact_field :address
|
|
|
|
end
|
|
|
|
|
2011-03-07 17:39:47 +00:00
|
|
|
def method_missing(key, *opts)
|
|
|
|
if key.to_s[-1..-1] == '='
|
|
|
|
@options[key.to_s[0..-2].to_sym] = opts.first
|
|
|
|
else
|
|
|
|
@options[key]
|
|
|
|
end
|
|
|
|
end
|
2011-03-07 21:38:20 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
def primary_contact_field(field)
|
|
|
|
if contact = primary_contact
|
|
|
|
contact.send(field)
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def primary_contact
|
|
|
|
@contacts.find(&:primary) || @contacts.sort.first
|
|
|
|
end
|
2011-03-07 17:39:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|