Class: ADIWG::Mdtranslator::Writers::Fgdc::Source

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

Instance Method Summary collapse

Constructor Details

#initialize(xml, hResponseObj) ⇒ Source



19
20
21
22
23
# File 'lib/adiwg/mdtranslator/writers/fgdc/classes/class_source.rb', line 19

def initialize(xml, hResponseObj)
   @xml = xml
   @hResponseObj = hResponseObj
   @NameSpace = ADIWG::Mdtranslator::Writers::Fgdc
end

Instance Method Details

#writeXML(hSource, aSourceCollection) ⇒ Object



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
# File 'lib/adiwg/mdtranslator/writers/fgdc/classes/class_source.rb', line 25

def writeXML(hSource, aSourceCollection)
   
   # skip if this source is already identified
   unless hSource[:sourceId].nil?
      return if aSourceCollection.include?(hSource[:sourceId])
      aSourceCollection << hSource[:sourceId]
   end
   if hSource[:sourceId].nil?
      @NameSpace.issueError(230)
   end

   @xml.tag!('srcinfo') do

      # classes used
      citationClass = Citation.new(@xml, @hResponseObj)
      timePeriodClass = TimePeriod.new(@xml, @hResponseObj)

      # source 2.5.1.1 (srccite) - source citation (required)
      # <- resourceLineage.source.sourceCitation
      unless hSource[:sourceCitation].empty?
         @xml.tag!('srccite') do
            citationClass.writeXML(hSource[:sourceCitation], [], 'lineage source')
         end
      end
      if hSource[:sourceCitation].empty?
         @NameSpace.issueWarning(231, nil, "source ID #{hSource[:sourceId]}")
      end

      # source 2.5.1.2 (srcscale) - source scale denominator
      # <- resourceLineage.source.spatialResolution.scaleFactor
      haveResolution = false
      unless hSource[:spatialResolution].empty?
         unless hSource[:spatialResolution].nil?
            haveResolution = true
            @xml.tag!('srcscale', hSource[:spatialResolution][:scaleFactor].to_s)
         end
      end
      if !haveResolution && @hResponseObj[:writerShowTags]
         @xml.tag!('srcscale')
      end

      # source 2.5.1.3 (typesrc) - type of source media (required)
      # <- resourceLineage.source.description
      unless hSource[:description].nil?
         @xml.tag!('typesrc', hSource[:description])
      end
      if hSource[:description].nil?
         @NameSpace.issueWarning(232, 'typesrc', "source ID #{hSource[:sourceId]}")
      end

      # source 2.5.1.4 (srctime) - source time period (required)
      # <- resourceLineage.source.scope.extents[0].temporalExtent[0].timePeriod
      haveTime = false
      unless hSource[:scope].empty?
         unless hSource[:scope][:extents].empty?
            unless hSource[:scope][:extents][0][:temporalExtents].empty?
               unless hSource[:scope][:extents][0][:temporalExtents][0][:timePeriod].empty?
                  haveTime = true
                  hTimePeriod = hSource[:scope][:extents][0][:temporalExtents][0][:timePeriod]
                  @xml.tag!('srctime') do
                     timePeriodClass.writeXML(hTimePeriod, 'srccurr')
                  end
               end
            end
         end
      end
      unless haveTime
         @NameSpace.issueWarning(233, nil, "source ID #{hSource[:sourceId]}")
      end

      # source 2.5.1.5 (srccitea) - source citation abbreviation (required)
      # <- resourceLineage.source.sourceId
      unless hSource[:sourceId].nil?
         @xml.tag!('srccitea', hSource[:sourceId])
      end
      if hSource[:sourceId].nil?
         @NameSpace.issueWarning(234, 'srccitea', "source ID #{hSource[:sourceId]}")
      end

      # source 2.5.1.6 (srccontr) - source contribution (required)
      # <- resourceLineage.source.description
      unless hSource[:description].nil?
         @xml.tag!('srccontr', hSource[:description])
      end
      if hSource[:description].nil?
         @NameSpace.issueWarning(235, 'srccontr', "source ID #{hSource[:sourceId]}")
      end

   end

end