2011-03-07 21:38:20 +00:00
|
|
|
module AVM
|
|
|
|
class Contact
|
|
|
|
FIELD_MAP = {
|
|
|
|
:zip => :postal_code,
|
|
|
|
:state => :state_province,
|
|
|
|
:province => :state_province
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:30:19 +00:00
|
|
|
HASH_FIELDS = [ :name, :email, :telephone, :address, :city, :state, :postal_code, :country ]
|
|
|
|
|
2011-03-07 21:38:20 +00:00
|
|
|
attr_accessor :primary
|
|
|
|
|
|
|
|
def initialize(info)
|
|
|
|
@info = Hash[info.collect { |key, value| [ FIELD_MAP[key] || key, value ] }]
|
|
|
|
@primary = false
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(key)
|
|
|
|
@info[FIELD_MAP[key] || key]
|
|
|
|
end
|
|
|
|
|
|
|
|
def <=>(other)
|
2011-03-17 17:30:19 +00:00
|
|
|
return -1 if primary?
|
2011-03-07 21:38:20 +00:00
|
|
|
self.name <=> other.name
|
|
|
|
end
|
2011-03-09 15:14:31 +00:00
|
|
|
|
|
|
|
def to_creator_list_element
|
|
|
|
%{<rdf:li>#{self.name}</rdf:li>}
|
|
|
|
end
|
2011-03-11 18:37:23 +00:00
|
|
|
|
|
|
|
def primary?
|
|
|
|
@primary
|
|
|
|
end
|
2011-03-17 17:30:19 +00:00
|
|
|
|
|
|
|
def to_h
|
|
|
|
Hash[HASH_FIELDS.collect { |key| [ key, send(key) ] } ]
|
|
|
|
end
|
2011-03-07 21:38:20 +00:00
|
|
|
end
|
|
|
|
end
|