class DarwinCore::Generator::EmlXml
Creates EML file with meta information about archive
Constants
- SCHEMA_DATA
Public Class Methods
new(data, path)
click to toggle source
# File lib/dwc_archive/generator_eml_xml.rb, line 18 def initialize(data, path) @data = data @path = path @write = "w:utf-8" end
Public Instance Methods
create()
click to toggle source
# File lib/dwc_archive/generator_eml_xml.rb, line 24 def create schema_data = { packageId: "#{@data[:id]}/#{timestamp}", system: @data[:system] || "http://globalnames.org" }.merge(SCHEMA_DATA) builder = Nokogiri::XML::Builder.new do |xml| xml.eml(schema_data) do build_body(xml) end end save_eml(builder) end
Private Instance Methods
build_abstract(xml)
click to toggle source
# File lib/dwc_archive/generator_eml_xml.rb, line 65 def build_abstract(xml) xml.abstract { xml.para(@data[:abstract]) } end
build_additional_metadata(xml)
click to toggle source
# File lib/dwc_archive/generator_eml_xml.rb, line 89 def build_additional_metadata(xml) xml.additionalMetadata do xml.metadata do xml.citation(@data[:citation]) xml.resourceLogoUrl(@data[:logo_url]) if @data[:logo_url] end end end
build_body(xml)
click to toggle source
# File lib/dwc_archive/generator_eml_xml.rb, line 39 def build_body(xml) build_dataset(xml) build_additional_metadata(xml) xml.parent.namespace = xml.parent.namespace_definitions.first end
build_contacts(xml, contacts)
click to toggle source
# File lib/dwc_archive/generator_eml_xml.rb, line 69 def build_contacts(xml, contacts) contacts.each { |contact| xml.contact { xml.references(contact) } } end
build_dataset(xml)
click to toggle source
# File lib/dwc_archive/generator_eml_xml.rb, line 52 def build_dataset(xml) xml.dataset(id: @data[:id]) do xml.title(@data[:title]) xml.license(@data[:license]) contacts = [] build_authors(xml, contacts) build_metadata_providers(xml) xml.pubDate(Time.now.to_s) build_abstract(xml) build_contacts(xml, contacts) end end
build_metadata_providers(xml)
click to toggle source
# File lib/dwc_archive/generator_eml_xml.rb, line 73 def build_metadata_providers(xml) @data[:metadata_providers].each do |a| xml.metadataProvider { build_person(xml, a) } end if @data[:metadata_providers] end
build_person(xml, data)
click to toggle source
# File lib/dwc_archive/generator_eml_xml.rb, line 98 def build_person(xml, data) a = data 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
save_eml(builder)
click to toggle source
# File lib/dwc_archive/generator_eml_xml.rb, line 45 def save_eml(builder) data = builder.to_xml f = open(File.join(@path, "eml.xml"), @write) f.write(data) f.close end
timestamp()
click to toggle source
# File lib/dwc_archive/generator_eml_xml.rb, line 110 def timestamp t = Time.now.getutc.to_a[0..5].reverse t[0..2] * ("-") + "::" + t[-3..-1] * (":") end