Module: ADIWG::Mdtranslator::Readers::MdJson::VerticalDatum

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

Class Method Summary collapse

Class Method Details

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



18
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/adiwg/mdtranslator/readers/mdJson/modules/module_verticalDatum.rb', line 18

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

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

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

   # instance classes needed in script
   intMetadataClass = InternalMetadata.new
   intDatum = intMetadataClass.newVerticalDatum

   outContext = 'vertical datum'
   outContext = inContext + ' > ' + outContext unless inContext.nil?

   # vertical datum - identifier {identifier} (required)
   if hDatum.has_key?('datumIdentifier')
      unless hDatum['datumIdentifier'].empty?
         hReturn = Identifier.unpack(hDatum['datumIdentifier'], responseObj, outContext)
         unless hReturn.nil?
            intDatum[:datumIdentifier] = hReturn
         end
      end
   end
   if intDatum[:datumIdentifier].empty?
      @MessagePath.issueError(921, responseObj, inContext)
   end

   # TODO remove when mdJson version 3
   # vertical datum - datum name (deprecated), move to datumIdentifier
   # skip datumName if identifier is already present
   if hDatum.has_key?('datumName')
      unless hDatum['datumName'] == ''
         @MessagePath.issueWarning(922, responseObj, inContext)
         if intDatum[:datumIdentifier].empty?
            intDatum[:datumIdentifier] = intMetadataClass.newIdentifier
            intDatum[:datumIdentifier][:identifier] = hDatum['datumName']
            @MessagePath.issueNotice(925, responseObj, inContext)
            @MessagePath.issueNotice(923, responseObj, inContext)
         end
      end
   end

   haveOthers  = 0

   # vertical datum - encoding method
   if hDatum.has_key?('encodingMethod')
      unless hDatum['encodingMethod'] == ''
         intDatum[:encodingMethod] = hDatum['encodingMethod']
         haveOthers += 1
      end
   end

   # vertical datum - is depth system {Boolean} (required)
   if hDatum.has_key?('isDepthSystem')
      if hDatum['isDepthSystem'] === true
         intDatum[:isDepthSystem] = true
      end
   end

   # vertical datum - vertical resolution
   if hDatum.has_key?('verticalResolution')
      unless hDatum['verticalResolution'] == ''
         intDatum[:verticalResolution] = hDatum['verticalResolution']
         haveOthers += 1
      end
   end

   # vertical datum - unit of measure
   if hDatum.has_key?('unitOfMeasure')
      unless hDatum['unitOfMeasure'] == ''
         intDatum[:unitOfMeasure] = hDatum['unitOfMeasure']
         haveOthers += 1
      end
   end

   # error messages
   unless haveOthers == 0 || haveOthers == 3
      @MessagePath.issueError(924, responseObj, inContext)
   end

   return intDatum

end