Class: ADIWG::Mdtranslator::Writers::Iso19110::ConventionalUnit

Inherits:
Object
  • Object
show all
Defined in:
lib/adiwg/mdtranslator/writers/iso19110/classes/class_conventionalUnit.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml, responseObj) ⇒ ConventionalUnit

Returns a new instance of ConventionalUnit.



18
19
20
21
# File 'lib/adiwg/mdtranslator/writers/iso19110/classes/class_conventionalUnit.rb', line 18

def initialize(xml, responseObj)
   @xml = xml
   @hResponseObj = responseObj
end

Instance Method Details

#writeXML(hConv) ⇒ Object



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
# File 'lib/adiwg/mdtranslator/writers/iso19110/classes/class_conventionalUnit.rb', line 23

def writeXML(hConv)

   # create and identity for the unit
   @hResponseObj[:writerMissingIdCount] = @hResponseObj[:writerMissingIdCount].succ
   unitID = 'unit' + @hResponseObj[:writerMissingIdCount]

   @xml.tag!('gml:ConventionalUnit', {'gml:id' => unitID}) do
      @xml.tag!('gml:identifier', {'codeSpace' => hConv[:codeSpace]}, hConv[:identifier])
      @xml.tag!('gml:name', hConv[:name])
      @xml.tag!('gml:catalogSymbol', hConv[:catalogSymbol])
      @xml.tag!('gml:conversionToPreferredUnit', {'uom' => hConv[:preferredUnit]}) do

         # two methods of conversion are available
         # factor and formula
         if !hConv[:factor].nil?
            # factor:
            #    y = factor * x
            #    y is in preferred units
            #    x is in provided units
            #    factor is conversion to preferred units
            @xml.tag!('gml:factor', hConv[:factor])
         else
            # formula:
            #    y = (a + bx) / (c + dx)
            #    y is in preferred units
            #    x is in provided units
            #    a,b,c,d are constants to convert to preferred units
            @xml.tag!('gml:formula') do
               @xml.tag!('gml:a', hConv[:a])
               @xml.tag!('gml:b', hConv[:b])
               @xml.tag!('gml:c', hConv[:c])
               @xml.tag!('gml:d', hConv[:d])
            end
         end

      end
   end

end