Module: ADIWG::Mdtranslator::Readers::MdJson::Attribute

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

Class Method Summary collapse

Class Method Details

.unpack(hAttribute, responseObj, inContext = nil) ⇒ 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/adiwg/mdtranslator/readers/mdJson/modules/module_attribute.rb', line 19

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

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

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

   # instance classes needed in script
   intMetadataClass = InternalMetadata.new
   intAttGroup = intMetadataClass.newAttribute

   outContext = 'attribute'
   outContext = inContext + ' > ' + outContext unless inContext.nil?

   # attribute group - sequence identifier
   if hAttribute.has_key?('sequenceIdentifier')
      unless hAttribute['sequenceIdentifier'] == ''
         intAttGroup[:sequenceIdentifier] = hAttribute['sequenceIdentifier']
      end
   end

   # attribute group - sequence identifier type (required if)
   unless intAttGroup[:sequenceIdentifier].nil?
      if hAttribute.has_key?('sequenceIdentifierType')
         unless hAttribute['sequenceIdentifierType'] == ''
            intAttGroup[:sequenceIdentifierType] = hAttribute['sequenceIdentifierType']
         end
      end
      if intAttGroup[:sequenceIdentifierType].nil?
         @MessagePath.issueError(41, responseObj, inContext)
      end
   end

   # attribute group - attribute description
   if hAttribute.has_key?('attributeDescription')
      unless hAttribute['attributeDescription'] == ''
         intAttGroup[:attributeDescription] = hAttribute['attributeDescription']
      end
   end

   # attribute group - attribute identifier [identifier]
   if hAttribute.has_key?('attributeIdentifier')
      aItems = hAttribute['attributeIdentifier']
      aItems.each do |item|
         hReturn = Identifier.unpack(item, responseObj, outContext)
         unless hReturn.nil?
            intAttGroup[:attributeIdentifiers] << hReturn
         end
      end
   end

   # attribute group - min value
   if hAttribute.has_key?('minValue')
      unless hAttribute['minValue'] == ''
         intAttGroup[:minValue] = hAttribute['minValue']
      end
   end

   # attribute group - max value
   if hAttribute.has_key?('maxValue')
      unless hAttribute['maxValue'] == ''
         intAttGroup[:maxValue] = hAttribute['maxValue']
      end
   end

   # attribute group - units (required if)
   unless intAttGroup[:minValue].nil? && intAttGroup[:maxValue].nil?
      if hAttribute.has_key?('units')
         unless hAttribute['units'] == ''
            intAttGroup[:units] = hAttribute['units']
         end
      end
      if intAttGroup[:units].nil?
         @MessagePath.issueError(42, responseObj, inContext)
      end
   end

   # attribute group - scale factor
   if hAttribute.has_key?('scaleFactor')
      unless hAttribute['scaleFactor'] == ''
         intAttGroup[:scaleFactor] = hAttribute['scaleFactor']
      end
   end

   if hAttribute.has_key?('rangeElementDescription')
      unless hAttribute['rangeElementDescription'].nil?
         intAttGroup[:rangeElementDescription] = []

         hAttribute['rangeElementDescription'].each do |item|
            intAttGroup[:rangeElementDescription] << RangeElementDescription.unpack(item, responseObj, outContext)
         end
      end
   end

   # attribute group - offset
   if hAttribute.has_key?('offset')
      unless hAttribute['offset'] == ''
         intAttGroup[:offset] = hAttribute['offset']
      end
   end

   # attribute group - mean value
   if hAttribute.has_key?('meanValue')
      unless hAttribute['meanValue'] == ''
         intAttGroup[:meanValue] = hAttribute['meanValue']
      end
   end

   # attribute group - number of values
   if hAttribute.has_key?('numberOfValues')
      unless hAttribute['numberOfValues'] == ''
         intAttGroup[:numberOfValues] = hAttribute['numberOfValues']
      end
   end

   # attribute group - standard deviation
   if hAttribute.has_key?('standardDeviation')
      unless hAttribute['standardDeviation'] == ''
         intAttGroup[:standardDeviation] = hAttribute['standardDeviation']
      end
   end

   # attribute group - bits per value
   if hAttribute.has_key?('bitsPerValue')
      unless hAttribute['bitsPerValue'] == ''
         intAttGroup[:bitsPerValue] = hAttribute['bitsPerValue']
      end
   end

   # attribute group - bound min
   if hAttribute.has_key?('boundMin')
      unless hAttribute['boundMin'] == ''
         intAttGroup[:boundMin] = hAttribute['boundMin']
      end
   end

   # attribute group - bound max
   if hAttribute.has_key?('boundMax')
      unless hAttribute['boundMax'] == ''
         intAttGroup[:boundMax] = hAttribute['boundMax']
      end
   end

   # attribute group - bound units (required if)
   unless intAttGroup[:boundMin].nil? && intAttGroup[:boundMax].nil?
      if hAttribute.has_key?('boundUnits')
         unless hAttribute['boundUnits'] == ''
            intAttGroup[:boundUnits] = hAttribute['boundUnits']
         end
      end
      if intAttGroup[:boundUnits].nil?
         @MessagePath.issueError(43, responseObj, inContext)
      end
   end

   # attribute group - peak response
   if hAttribute.has_key?('peakResponse')
      unless hAttribute['peakResponse'] == ''
         intAttGroup[:peakResponse] = hAttribute['peakResponse']
      end
   end

   # attribute group - tone gradations
   if hAttribute.has_key?('toneGradations')
      unless hAttribute['toneGradations'] == ''
         intAttGroup[:toneGradations] = hAttribute['toneGradations']
      end
   end

   # attribute group - band boundary definition
   if hAttribute.has_key?('bandBoundaryDefinition')
      unless hAttribute['bandBoundaryDefinition'] == ''
         intAttGroup[:bandBoundaryDefinition] = hAttribute['bandBoundaryDefinition']
      end
   end

   # attribute group - nominal spatial resolution {measure}
   if hAttribute.has_key?('nominalSpatialResolution')
      unless hAttribute['nominalSpatialResolution'] == ''
         intAttGroup[:nominalSpatialResolution] = hAttribute['nominalSpatialResolution']
      end
   end

   # attribute group - transfer function type
   if hAttribute.has_key?('transferFunctionType')
      unless hAttribute['transferFunctionType'] == ''
         intAttGroup[:transferFunctionType] = hAttribute['transferFunctionType']
      end
   end

   # attribute group - transmitted polarization
   if hAttribute.has_key?('transmittedPolarization')
      unless hAttribute['transmittedPolarization'] == ''
         intAttGroup[:transmittedPolarization] = hAttribute['transmittedPolarization']
      end
   end

   # attribute group - detected polarization
   if hAttribute.has_key?('detectedPolarization')
      unless hAttribute['detectedPolarization'] == ''
         intAttGroup[:detectedPolarization] = hAttribute['detectedPolarization']
      end
   end

   return intAttGroup

end