Module: ADIWG::Mdtranslator::Readers::MdJson::Funding

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

Class Method Summary collapse

Class Method Details

.unpack(hFunding, responseObj) ⇒ Object



19
20
21
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
# File 'lib/adiwg/mdtranslator/readers/mdJson/modules/module_funding.rb', line 19

def self.unpack(hFunding, responseObj)

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

   # return nil object if input is empty
   if hFunding.empty?
      @MessagePath.issueWarning(300, responseObj)
      return nil
   end

   # instance classes needed in script
   intMetadataClass = InternalMetadata.new
   intFunding = intMetadataClass.newFunding

   outContext = 'funding'

   # funding - description
   if hFunding.has_key?('description')
      unless hFunding['description'] == ''
         intFunding[:description] = hFunding['description']
      end
   end

   # funding - timePeriod (required if)
   if hFunding.has_key?('timePeriod')
      hObject = hFunding['timePeriod']
      unless hObject.empty?
         hReturn = TimePeriod.unpack(hObject, responseObj, outContext)
         unless hReturn.nil?
            intFunding[:timePeriod] = hReturn
         end
      end
   end

   # funding - allocation [] (required if)
   if hFunding.has_key?('allocation')
      aItems = hFunding['allocation']
      aItems.each do |item|
         hReturn = Allocation.unpack(item, responseObj)
         unless hReturn.nil?
            intFunding[:allocations] << hReturn
         end
      end
   end

   # error messages
   if intFunding[:allocations].empty? && intFunding[:timePeriod].empty?
      @MessagePath.issueError(301, responseObj)
   end

   return intFunding

end