Class: Labimotion::BuildTemplateDoiXml

Inherits:
Object
  • Object
show all
Includes:
DataCitePublisher
Defined in:
lib/labimotion/usecases/build_template_doi_xml.rb

Overview

Builds the DataCite (kernel-4) metadata XML for a LabIMotion template DOI. The same XML is uploaded to DataCite at release time and shown in the UI preview, so what users see is exactly what gets sent. A template has a single DOI; the ERB template binds to this instance, so the methods below are its accessors.

Constant Summary collapse

GEM_TEMPLATE_PATH =

The template ships with the gem. A host app may still override it by placing its own copy at HOST_TEMPLATE_PATH, which is how it used to be sourced — hence the lookup order below.

File.expand_path('../libs/data/datacite/labimotion_template.html.erb', __dir__)
HOST_TEMPLATE_PATH =
'app/publish/datacite_metadata_labimotion_template.html.erb'
RESOURCE_LABEL =
{
  'element' => 'LabIMotion Element Template',
  'segment' => 'LabIMotion Segment Template',
  'dataset' => 'LabIMotion Dataset Template'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(record, doi = nil) ⇒ BuildTemplateDoiXml

Returns a new instance of BuildTemplateDoiXml.



26
27
28
29
# File 'lib/labimotion/usecases/build_template_doi_xml.rb', line 26

def initialize(record, doi = nil)
  @record = record
  @doi = doi || ::Doi.labimotion_latest_doi(record)
end

Instance Method Details

#callObject

Returns the XML string, or nil when no DOI has been reserved yet.



32
33
34
35
36
# File 'lib/labimotion/usecases/build_template_doi_xml.rb', line 32

def call
  return nil if @doi.nil?

  ERB.new(File.read(template_path), trim_mode: '-').result(binding)
end