lib/adiwg/mdtranslator/readers/mdJson/modules/module_address.rb in adiwg-mdtranslator-2.9.2 vs lib/adiwg/mdtranslator/readers/mdJson/modules/module_address.rb in adiwg-mdtranslator-2.10.0

- old
+ new

@@ -1,101 +1,101 @@ # unpack address # Reader - ADIwg JSON to internal data structure # History: -# Stan Smith 2016-10-03 refactored for mdJson 2.0 -# Stan Smith 2015-07-14 refactored to remove global namespace constants -# Stan Smith 2015-06-22 replace global ($response) with passed in object (responseObj) -# Stan Smith 2014-12-30 refactored -# ... electronicMailAddresses into internal object -# Stan Smith 2014-12-19 prevented passing blank deliveryPoints and -# Stan Smith 2014-12-15 refactored to handle namespacing readers and writers -# Stan Smith 2013-10-21 original script +# Stan Smith 2018-02-18 refactored error and warning messaging +# Stan Smith 2016-10-03 refactored for mdJson 2.0 +# Stan Smith 2015-07-14 refactored to remove global namespace constants +# Stan Smith 2015-06-22 replace global ($response) with passed in object (responseObj) +# Stan Smith 2014-12-30 refactored +# ... electronicMailAddresses into internal object +# Stan Smith 2014-12-19 prevented passing blank deliveryPoints and +# Stan Smith 2014-12-15 refactored to handle namespacing readers and writers +# Stan Smith 2013-10-21 original script module ADIWG - module Mdtranslator - module Readers - module MdJson + module Mdtranslator + module Readers + module MdJson - module Address + module Address - def self.unpack(hAddress, responseObj) + def self.unpack(hAddress, responseObj) - # return nil object if input is empty - if hAddress.empty? - responseObj[:readerExecutionMessages] << 'Address object is empty' - responseObj[:readerExecutionPass] = false - return nil - end + # return nil object if input is empty + if hAddress.empty? + responseObj[:readerExecutionMessages] << 'WARNING: mdJson reader: address object is empty' + return nil + end - # instance classes needed in script - intMetadataClass = InternalMetadata.new - intAdd = intMetadataClass.newAddress + # instance classes needed in script + intMetadataClass = InternalMetadata.new + intAdd = intMetadataClass.newAddress - # address - address type [adiwg_addressType] (required) - if hAddress.has_key?('addressType') - hAddress['addressType'].each do |item| - if item != '' - intAdd[:addressTypes] << item - end - end + # address - address type [adiwg_addressType] (required) + if hAddress.has_key?('addressType') + hAddress['addressType'].each do |item| + unless item == '' + intAdd[:addressTypes] << item end - if intAdd[:addressTypes].empty? - responseObj[:readerExecutionMessages] << 'Address Type is missing' - responseObj[:readerExecutionPass] = false - return nil - end + end + end + if intAdd[:addressTypes].empty? + responseObj[:readerExecutionMessages] << 'ERROR: mdJson reader: address type is missing' + responseObj[:readerExecutionPass] = false + return nil + end - # address - description - if hAddress.has_key?('description') - if hAddress['description'] != '' - intAdd[:description] = hAddress['description'] - end - end + # address - description + if hAddress.has_key?('description') + unless hAddress['description'] == '' + intAdd[:description] = hAddress['description'] + end + end - # address - delivery point - if hAddress.has_key?('deliveryPoint') - hAddress['deliveryPoint'].each do |item| - if item != '' - intAdd[:deliveryPoints] << item - end - end + # address - delivery point + if hAddress.has_key?('deliveryPoint') + hAddress['deliveryPoint'].each do |item| + unless item == '' + intAdd[:deliveryPoints] << item end + end + end - # address - city - if hAddress.has_key?('city') - if hAddress['city'] != '' - intAdd[:city] = hAddress['city'] - end - end + # address - city + if hAddress.has_key?('city') + unless hAddress['city'] == '' + intAdd[:city] = hAddress['city'] + end + end - # address - admin area - if hAddress.has_key?('administrativeArea') - if hAddress['administrativeArea'] != '' - intAdd[:adminArea] = hAddress['administrativeArea'] - end - end + # address - admin area + if hAddress.has_key?('administrativeArea') + unless hAddress['administrativeArea'] == '' + intAdd[:adminArea] = hAddress['administrativeArea'] + end + end - # address - postal code - if hAddress.has_key?('postalCode') - if hAddress['postalCode'] != '' - intAdd[:postalCode] = hAddress['postalCode'] - end - end + # address - postal code + if hAddress.has_key?('postalCode') + unless hAddress['postalCode'] == '' + intAdd[:postalCode] = hAddress['postalCode'] + end + end - # address - country - if hAddress.has_key?('country') - if hAddress['country'] != '' - intAdd[:country] = hAddress['country'] - end - end + # address - country + if hAddress.has_key?('country') + unless hAddress['country'] == '' + intAdd[:country] = hAddress['country'] + end + end - return intAdd + return intAdd - end + end - end - end - end - end + + end + end + end end