Class: CI_Citation

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

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ CI_Citation

Returns a new instance of CI_Citation.



21
22
23
# File 'lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_citation.rb', line 21

def initialize(xml)
  @xml = xml
end

Instance Method Details

#writeXML(hCitation) ⇒ 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
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
# File 'lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_citation.rb', line 25

def writeXML(hCitation)

  # classes used in MD_Metadata
  presFormClass = CI_PresentationFormCode.new(@xml)
  rPartyClass = CI_ResponsibleParty.new(@xml)
  dateClass = CI_Date.new(@xml)
  idClass = MD_Identifier.new(@xml)

  @xml.tag!('gmd:CI_Citation') do

    # citation - title - required
    s = hCitation[:citTitle]
    if s.nil?
      @xml.tag!('gmd:title',{'gco:nilReason'=>'missing'})
    else
      @xml.tag!('gmd:title') do
        @xml.tag!('gco:CharacterString',s)
      end
    end

    # citation - date - required
    aDate = hCitation[:citDate]
    if aDate.empty?
      @xml.tag!('gmd:date', {'gco:nilReason' => 'missing'})
    else
      aDate.each do |hDate|
        @xml.tag!('gmd:date') do
          dateClass.writeXML(hDate)
        end
      end
    end

    # citation - edition
    s = hCitation[:citEdition]
    if !s.nil?
      @xml.tag!('gmd:edition') do
        @xml.tag!('gco:CharacterString',s)
      end
    elsif $showAllTags
      @xml.tag!('gmd:edition')
    end

    # citation - resource identifiers - MD_Identifier
    # do not process ISBN and ISSN as MD_identifier(s)
    # ... these are processed separately in ISO 19115-2
    aResIDs = hCitation[:citResourceIDs]
    if !aResIDs.empty?
      aResIDs.each do |hResID|
        if !hResID[:identifierType].nil?
          next if hResID[:identifierType].downcase == 'isbn'
          next if hResID[:identifierType].downcase == 'issn'
        end
        @xml.tag!('gmd:identifier') do
          idClass.writeXML(hResID)
        end
      end
    elsif $showAllTags
      @xml.tag!('gmd:identifier')
    end

    # citation - cited responsible party
    aResParty = hCitation[:citResponsibleParty]
    if !aResParty.empty?
      aResParty.each do |rParty|
        @xml.tag!('gmd:citedResponsibleParty') do
          rPartyClass.writeXML(rParty)
        end
      end
    elsif $showAllTags
      @xml.tag!('gmd:citedResponsibleParty')
    end

    # citation - presentation forms - CI_PresentationFormCode
    aPresForms = hCitation[:citResourceForms]
    if !aPresForms.empty?
      aPresForms.each do |presForm|
        @xml.tag!('gmd:presentationForm') do
          presFormClass.writeXML(presForm)
        end
      end
    elsif $showAllTags
      @xml.tag!('gmd:presentationForm')
    end

    # citation - ISBN
    needTag = true
    aResIDs = hCitation[:citResourceIDs]
    if !aResIDs.empty?
      aResIDs.each do |hResID|
        if !hResID[:identifierType].nil?
          if hResID[:identifierType].downcase == 'isbn'
            s = hResID[:identifier]
            if !s.nil?
              @xml.tag!('gmd:ISBN') do
                @xml.tag!('gco:CharacterString',s)
                needTag = false
              end
            end
          end
        end
      end
    end
    if $showAllTags && needTag
      @xml.tag!('gmd:ISBN')
    end

    # citation - ISSN
    needTag = true
    aResIDs = hCitation[:citResourceIDs]
    if !aResIDs.empty?
      aResIDs.each do |hResID|
        if !hResID[:identifierType].nil?
          if hResID[:identifierType].downcase == 'issn'
            s = hResID[:identifier]
            if !s.nil?
              @xml.tag!('gmd:ISSN') do
                @xml.tag!('gco:CharacterString',s)
                needTag = false
              end
            end
          end
        end
      end
    end
    if $showAllTags && needTag
      @xml.tag!('gmd:ISSN')
    end

  end

end