Module: ADIWG::Mdtranslator::Readers::MdJson::Address

Defined in:
lib/adiwg/mdtranslator/readers/mdJson/modules/module_address.rb

Class Method Summary collapse

Class Method Details

.unpack(hAddress, responseObj, inContext = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/adiwg/mdtranslator/readers/mdJson/modules/module_address.rb', line 22

def self.unpack(hAddress, responseObj, inContext = nil)

   @MessagePath = ADIWG::Mdtranslator::Readers::MdJson::MdJson

   # return nil object if input is empty
   if hAddress.empty?
      @MessagePath.issueWarning(10, responseObj, inContext)
      return nil
   end

   # instance classes needed in script
   intMetadataClass = .new
   intAdd = intMetadataClass.newAddress

   # address - address type [adiwg_addressType] (required)
   if hAddress.has_key?('addressType')
      hAddress['addressType'].each do |item|
         unless item == ''
            intAdd[:addressTypes] << item
         end
      end
   end
   if intAdd[:addressTypes].empty?
      @MessagePath.issueError(11, responseObj, inContext)
   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|
         unless item == ''
            intAdd[:deliveryPoints] << item
         end
      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')
      unless hAddress['administrativeArea'] == ''
         intAdd[:adminArea] = hAddress['administrativeArea']
      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')
      unless hAddress['country'] == ''
         intAdd[:country] = hAddress['country']
      end
   end

   return intAdd

end