Module: Blacklight::Document::DublinCore

Defined in:
app/models/concerns/blacklight/document/dublin_core.rb

Overview

This module provide Dublin Core export based on the document’s semantic values

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(document) ⇒ Object



7
8
9
10
# File 'app/models/concerns/blacklight/document/dublin_core.rb', line 7

def self.extended(document)
  # Register our exportable formats
  Blacklight::Document::DublinCore.register_export_formats(document)
end

.register_export_formats(document) ⇒ Object



12
13
14
15
16
# File 'app/models/concerns/blacklight/document/dublin_core.rb', line 12

def self.register_export_formats(document)
  document.will_export_as(:xml)
  document.will_export_as(:dc_xml, "text/xml")
  document.will_export_as(:oai_dc_xml, "text/xml")
end

Instance Method Details

#dublin_core_field_namesObject



18
19
20
# File 'app/models/concerns/blacklight/document/dublin_core.rb', line 18

def dublin_core_field_names
  [:contributor, :coverage, :creator, :date, :description, :format, :identifier, :language, :publisher, :relation, :rights, :source, :subject, :title, :type]
end

#export_as_oai_dc_xmlObject Also known as: export_as_xml, export_as_dc_xml

dublin core elements are mapped against the #dublin_core_field_names whitelist.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/concerns/blacklight/document/dublin_core.rb', line 23

def export_as_oai_dc_xml
  xml = Builder::XmlMarkup.new
  xml.tag!("oai_dc:dc",
           'xmlns:oai_dc' => "http://www.openarchives.org/OAI/2.0/oai_dc/",
           'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
           'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
           'xsi:schemaLocation' => %(http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd)) do
    to_semantic_values.select { |field, _values| dublin_core_field_name? field }.each do |field, values|
      Array.wrap(values).each do |v|
        xml.tag! "dc:#{field}", v
      end
    end
  end
  xml.target!
end