Refactored contact attribute assignment

This commit is contained in:
Andres Keskküla 2014-08-15 11:52:43 +03:00
parent 5b91acb343
commit 6bcf508fac
7 changed files with 94 additions and 33 deletions

View file

@ -67,6 +67,32 @@ class Contact < ActiveRecord::Base
end
class << self
def extract_attributes ph, type=:create
contact_hash = {
#code: ph[:id],
phone: ph[:voice],
ident: ph[:ident],
#ident_type: ident_type,
email: ph[:email]
}
contact_hash = contact_hash.merge({
name: ph[:postalInfo][:name],
org_name: ph[:postalInfo][:org]
}) if ph[:postalInfo].is_a? Hash
contact_hash[:code] = ph[:id] if type == :create
contact_hash.delete_if { |k, v| v.nil? }
end
def ident_type code
end
def check_availability(codes)
codes = [codes] if codes.is_a?(String)