mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 00:12:03 +02:00
Refactored contact attribute assignment
This commit is contained in:
parent
5b91acb343
commit
6bcf508fac
7 changed files with 94 additions and 33 deletions
|
@ -1,4 +1,20 @@
|
|||
class Address < ActiveRecord::Base
|
||||
belongs_to :contact
|
||||
belongs_to :country
|
||||
|
||||
class << self
|
||||
def extract_attributes ah, type=:create
|
||||
address_hash = {}
|
||||
address_hash = ({
|
||||
country_id: Country.find_by(iso: ah[:cc]).try(:id),
|
||||
city: ah[:city],
|
||||
street: ah[:street][0],
|
||||
street2: ah[:street][1],
|
||||
street3: ah[:street][2],
|
||||
zip: ah[:pc]
|
||||
}) if ah.is_a?(Hash)
|
||||
|
||||
address_hash.delete_if { |k, v| v.nil? }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue