Class: CI_Telephone

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

Overview

History: Stan Smith 2013-08-12 original script

Stan Smith 2014-05-14 reorganized for JSON schema 0.4.0

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ CI_Telephone

Returns a new instance of CI_Telephone.



10
11
12
# File 'lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_telephone.rb', line 10

def initialize(xml)
  @xml = xml
end

Instance Method Details

#writeXML(aPhones) ⇒ Object



14
15
16
17
18
19
20
21
22
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_telephone.rb', line 14

def writeXML(aPhones)

    # ISO requires phones to be in proper order (voice, fax)
  # Need to count phones of each type to be able to include empty tag
  voiceCount = 0
  faxCount = 0
  aPhones.each do |hPhone|
    if hPhone[:phoneServiceType].nil?
      hPhone[:phoneServiceType] = 'voice'
    end
    if hPhone[:phoneServiceType] == 'voice'
      voiceCount += 1
    end
    if hPhone[:phoneServiceType] == 'fax'
      faxCount += 1
    end
  end

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

    # phone - voice phones
    if voiceCount > 0
      aPhones.each do |hPhone|
        if hPhone[:phoneServiceType] == 'voice'
          pName = hPhone[:phoneName]
          pNumber = hPhone[:phoneNumber]
          if pName.nil?
            s = pNumber
          else
            s = pName + ': ' + pNumber
          end
          @xml.tag!('gmd:voice') do
            @xml.tag!('gco:CharacterString',s)
          end
        end
      end
    elsif $showAllTags
      @xml.tag!('gmd:voice')
    end

    # phone - fax phones
    if faxCount > 0
      aPhones.each do |hPhone|
        if hPhone[:phoneServiceType] == 'fax'
          pName = hPhone[:phoneName]
          pNumber = hPhone[:phoneNumber]
          if pName.nil?
            s = pNumber
          else
            s = pName + ': ' + pNumber
          end
          @xml.tag!('gmd:facsimile') do
            @xml.tag!('gco:CharacterString',s)
          end
        end
      end
    elsif $showAllTags
      @xml.tag!('gmd:facsimile')
    end
  end

end