Class: DarwinCore::Generator::EmlXml

Inherits:
Object
  • Object
show all
Defined in:
lib/dwc-archive/generator_eml_xml.rb

Instance Method Summary collapse

Constructor Details

#initialize(data, path) ⇒ EmlXml

Returns a new instance of EmlXml.



5
6
7
8
9
# File 'lib/dwc-archive/generator_eml_xml.rb', line 5

def initialize(data, path)
  @data = data
  @path = path
  @write = 'w:utf-8'
end

Instance Method Details

#createObject



11
12
13
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/dwc-archive/generator_eml_xml.rb', line 11

def create
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.eml(:packageId      => "%s/%s" % [@data[:id], timestamp],
      :system               => @data[:system] || "http://globalnames.org",
      :'xml:lang'           => "en",
      :'xmlns:eml'          => "eml://ecoinformatics.org/eml-2.1.1",
      :'xmlns:md'           => "eml://ecoinformatics.org/methods-2.1.1",
      :'xmlns:proj'         => "eml://ecoinformatics.org/project-2.1.1",
      :'xmlns:d'            => "eml://ecoinformatics.org/dataset-2.1.1",
      :'xmlns:res'          => "eml://ecoinformatics.org/resource-2.1.1",
      :'xmlns:dc'           => "http://purl.org/dc/terms/",
      :'xmlns:xsi'          => "http://www.w3.org/2001/XMLSchema-instance",
      :'xsi:schemaLocation' => "eml://ecoinformatics.org/eml-2.1.1 http://rs.gbif.org/schema/eml-gbif-profile/1.0.1/eml.xsd") do
      xml.dataset(:id => @data[:id]) do
        xml.title(@data[:title])
        xml.license(@data[:license])
        contacts = []
        @data[:authors].each_with_index do |a, i|
          creator_id = i + 1
          contacts << creator_id
          xml.creator(:id => creator_id, :scope => 'document') do
            xml.individualName do
              xml.givenName(a[:first_name])
              xml.surName(a[:last_name])
            end
            xml.organizationName(a[:organization]) if a[:organization]
            xml.positionName(a[:position]) if a[:position]
            xml.onlineUrl(a[:url]) if a[:url]
            xml.electronicMailAddress(a[:email])
          end
        end
        @data[:metadata_providers].each_with_index do |a, i|
          xml.metadataProvider do
            xml.individualName do
              xml.givenName(a[:first_name])
              xml.surName(a[:last_name])
            end
            xml.organizationName(a[:organization]) if a[:organization]
            xml.positionName(a[:position]) if a[:position]
            xml.onlineUrl(a[:url]) if a[:url]
            xml.electronicMailAddress(a[:email])
          end
        end if @data[:metadata_providers]
        xml.pubDate(Time.now.to_s)
        xml.abstract() do
          xml.para(@data[:abstract])
        end
        contacts.each do |contact|
          xml.contact { xml.references(contact) }
        end
      end
      xml. do
        xml. do
          xml.citation(@data[:citation])
          xml.resourceLogoUrl(@data[:logo_url]) if @data[:logo_url]
        end
      end
      xml.parent.namespace = xml.parent.namespace_definitions.first
    end
  end
  data = builder.to_xml
  f = open(File.join(@path, 'eml.xml'), @write)
  f.write(data)
  f.close
end