Class: ADIWG::Mdtranslator::Writers::Iso19115_3::CI_Contact

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

Instance Method Summary collapse

Constructor Details

#initialize(xml, hResponseObj) ⇒ CI_Contact



19
20
21
22
# File 'lib/adiwg/mdtranslator/writers/iso19115_3/classes/class_contact.rb', line 19

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

Instance Method Details

#writeXML(hContact) ⇒ Object



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
# File 'lib/adiwg/mdtranslator/writers/iso19115_3/classes/class_contact.rb', line 24

def writeXML(hContact)

   # classes used
   phoneClass = CI_Telephone.new(@xml, @hResponseObj)
   addressClass = CI_Address.new(@xml, @hResponseObj)
   emailClass = Email.new(@xml, @hResponseObj)
   resourceClass = CI_OnlineResource.new(@xml, @hResponseObj)

   # outContext
   outContext = 'contact information'
   outContext +=  ' ' + hContact[:name] unless hContact[:name].nil?
   outContext += ' (' + hContact[:contactId] + ')' unless hContact[:contactId].nil?

   @xml.tag!('cit:CI_Contact') do

      # contact - phones [] {CI_Telephone}
      # pass phone array to phoneClass
      # ... need to output separate phone tags for each service
      unless hContact[:phones].empty?
         phoneClass.writeXML(hContact[:phones], outContext)
      end
      if hContact[:phones].empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('cit:phone')
      end

      # contact - address [] {CI_Address}
      aAddress = hContact[:addresses]
      aAddress.each do |hAddress|
         @xml.tag!('cit:address') do
            addressClass.writeXML(hAddress)
         end
      end
      if aAddress.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('cit:address')
      end

      # contact - email address [] {CI_Address}
      # in 19115-3 email addresses are associated with mailing addresses
      # in mdJson email addresses are associated with the contact
      # so email addresses are written into a separate address block for the contact
      unless hContact[:eMailList].empty?
         @xml.tag!('cit:address') do
            emailClass.writeXML(hContact[:eMailList])
         end
      end

      # contact - online resource [] {CI_OnlineResource}
      aOlResources = hContact[:onlineResources]
      aOlResources.each do |hOnline|
         @xml.tag!('cit:onlineResource') do
            resourceClass.writeXML(hOnline, outContext)
         end
      end
      if aOlResources.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('cit:onlineResource')
      end

      # contact - hours of service []
      aHours = hContact[:hoursOfService]
      aHours.each do |hours|
         @xml.tag!('cit:hoursOfService') do
            @xml.tag!('gco:CharacterString', hours)
         end
      end
      if aHours.empty? && @hResponseObj[:writerShowTags]
         @xml.tag!('cit:hoursOfService')
      end

      # contact - contact instructions
      unless hContact[:contactInstructions].nil?
         @xml.tag!('cit:contactInstructions') do
            @xml.tag!('gco:CharacterString', hContact[:contactInstructions])
         end
      end
      if hContact[:contactInstructions].nil? && @hResponseObj[:writerShowTags]
         @xml.tag!('cit:contactInstructions')
      end

      # contact - contact type
      unless hContact[:contactType].nil?
         @xml.tag!('cit:contactType') do
            @xml.tag!('gco:CharacterString', hContact[:contactType])
         end
      end
      if hContact[:contactType].nil? && @hResponseObj[:writerShowTags]
         @xml.tag!('cit:contactType')
      end

   end # CI_Contact tag
end