lib/adiwg/mdtranslator/writers/iso/units/class_conventionalUnit.rb in adiwg-mdtranslator-0.10.2 vs lib/adiwg/mdtranslator/writers/iso/units/class_conventionalUnit.rb in adiwg-mdtranslator-0.12.0
- old
+ new
@@ -1,53 +1,64 @@
# ISO <<Class>> ConventionalUnit
# writer output in XML
# History:
# Stan Smith 2014-12-03 original script
+# Stan Smith 2014-12-12 refactored to handle namespacing readers and writers
-class ConventionalUnit
+module ADIWG
+ module Mdtranslator
+ module Writers
+ module Iso
- def initialize(xml)
- @xml = xml
- end
+ class ConventionalUnit
- def writeXML(hConv)
+ def initialize(xml)
+ @xml = xml
+ end
- # create and identity for the unit
- $idCount = $idCount.succ
- unitID = 'unit' + $idCount
+ def writeXML(hConv)
- @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
+ # create and identity for the unit
+ $idCount = $idCount.succ
+ unitID = 'unit' + $idCount
- # 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
+ @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
- end
- end
+ # 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
+ end
+
+ end
+
+ end
+ end
+ end
end