lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_contact.rb in adiwg-mdtranslator-2.0.0rc8 vs lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_contact.rb in adiwg-mdtranslator-2.0.0rc9
- old
+ new
@@ -1,45 +1,124 @@
+# sbJson 1.0 writer
+
+# History:
+# Stan Smith 2017-05-25 refactored for mdJson/mdTranslator 2.0
+# Josh Bradley original script
+
require 'jbuilder'
+require_relative 'sbJson_codelists'
+require_relative 'sbJson_hours'
module ADIWG
- module Mdtranslator
- module Writers
- module SbJson
- module Contact
- def self.build(intObj)
- Jbuilder.new do |json|
- if intObj[:internal]
- json.nil!
- else
- type = intObj[:indName].nil? ? 'organization' : 'person'
- json.name intObj[:indName] || intObj[:orgName]
- json.contactType type
- json.type intObj[:primaryRole]
- json.email intObj[:address][:eMailList][0] unless intObj[:address].empty?
- json.organization type == 'person' ? {:displayText => intObj[:orgName]} : nil
- json.primaryLocation do
- json.officePhone intObj[:phones].collect { |ph|
- ph[:phoneNumber] if ph[:phoneServiceType] == 'voice'
- }.reject(&:nil?).first
- json.faxPhone intObj[:phones].collect { |ph|
- ph[:phoneNumber] if ph[:phoneServiceType] == 'fax'
- }.reject(&:nil?).first
- json.streetAddress do
- add = intObj[:address]
- unless [:deliveryPoints].empty?
- json.line1 add[:deliveryPoints][0]
- json.line2 add[:deliveryPoints][1]
- end
- json.city add[:city]
- json.state add[:adminArea]
- json.zip add[:postalCode]
- json.country add[:country]
- end unless intObj[:address].empty?
- end
- end
- end
- end
- end
+ module Mdtranslator
+ module Writers
+ module SbJson
+
+ module Contact
+
+ @Namespace = ADIWG::Mdtranslator::Writers::SbJson
+
+ def self.get_contact_list(intObj)
+
+ # gather all responsibility objects in intObj
+ aResponsibility = @Namespace.nested_objs_by_element(intObj, 'roleName')
+
+ # make a list of unique role/party contacts
+ aContactList = []
+ aResponsibility.each do |hResponsibility|
+ role = hResponsibility[:roleName]
+ hResponsibility[:parties].each do |hParty|
+ aContactList << { :role => role, :index => hParty[:contactIndex] }
+ end
+ end
+
+ aContactList = aContactList.uniq
+
+ end
+
+ def self.build(hParty)
+
+ Jbuilder.new do |json|
+
+ role = hParty[:role]
+ hContact = @Namespace.get_contact_by_index(hParty[:index])
+
+ unless hContact.empty?
+
+ type = hContact[:isOrganization] ? 'organization' : 'person'
+
+ orgName = nil
+ unless hContact[:memberOfOrgs].empty?
+ orgContact = @Namespace.get_contact_by_id(hContact[:memberOfOrgs][0])
+ orgName = orgContact[:name]
+ end
+ logoUrl = nil
+ unless hContact[:logos].empty?
+ logo0 = hContact[:logos][0]
+ unless logo0[:graphicURI].empty?
+ logoUrl = logo0[:graphicURI][0][:olResURI]
+ end
+ end
+
+ json.name hContact[:name]
+ json.contactType type
+ json.personalTitle hContact[:positionName] if type == 'person'
+ sbRole = Codelists.codelist_iso_to_sb('iso_sb_role', :isoCode => role)
+ json.type sbRole = sbRole.nil? ? role : sbRole
+ json.email hContact[:eMailList][0] unless hContact[:eMailList].empty?
+ json.hours Hours.build(hContact[:hoursOfService]) unless hContact[:hoursOfService].empty?
+ json.instructions hContact[:contactInstructions]
+ json.tty hContact[:phones].collect {|ph| ph[:phoneNumber] if
+ ph[:phoneServiceTypes].include?('tty')}.reject(&:nil?).first
+ json.organization {json.displayText orgName} unless orgName.nil?
+ json.logoUrl logoUrl unless logoUrl.nil?
+
+ if !hContact[:addresses].empty? || !hContact[:phones].empty?
+ json.primaryLocation do
+ unless hContact[:phones].empty?
+ json.officePhone hContact[:phones].collect {|ph| ph[:phoneNumber] if
+ ph[:phoneServiceTypes].include?('voice')}.reject(&:nil?).first
+ json.faxPhone hContact[:phones].collect {|ph| ph[:phoneNumber] if
+ ph[:phoneServiceTypes].include?('fax')}.reject(&:nil?).first
+ end
+ unless hContact[:addresses].empty?
+ aAddress = hContact[:addresses]
+ json.description aAddress[0][:description]
+ aAddress.each do |hAddress|
+ if hAddress[:addressTypes].include?('physical')
+ json.streetAddress do
+ unless hAddress[:deliveryPoints].empty?
+ json.line1 hAddress[:deliveryPoints][0]
+ json.line2 hAddress[:deliveryPoints][1]
+ end
+ json.city hAddress[:city]
+ json.state hAddress[:adminArea]
+ json.zip hAddress[:postalCode]
+ json.country hAddress[:country]
+ end
+ end
+ if hAddress[:addressTypes].include?('mailing')
+ json.mailAddress do
+ unless hAddress[:deliveryPoints].empty?
+ json.line1 hAddress[:deliveryPoints][0]
+ json.line2 hAddress[:deliveryPoints][1]
+ end
+ json.city hAddress[:city]
+ json.state hAddress[:adminArea]
+ json.zip hAddress[:postalCode]
+ json.country hAddress[:country]
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+
+ end # build
+ end # Module Contacts
+
+ end
end
- end
- end
+ end
end