Class: Datacite::Mapping::FromCocina::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/datacite/mapping/from_cocina/attributes.rb

Overview

Transform the Cocina::Models::DRO to a DataCite request attributes payload

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cocina_object:) ⇒ Attributes

Returns a new instance of Attributes.



17
18
19
20
21
22
# File 'lib/datacite/mapping/from_cocina/attributes.rb', line 17

def initialize(cocina_object:)
  @cocina_object = cocina_object

  # Set the time zone
  Time.zone = 'Pacific Time (US & Canada)'
end

Instance Attribute Details

#cocina_objectObject (readonly)

Returns the value of attribute cocina_object.



24
25
26
# File 'lib/datacite/mapping/from_cocina/attributes.rb', line 24

def cocina_object
  @cocina_object
end

Class Method Details

.buildHash

Returns Hash of DataCite attributes, conforming to the DataCite API Schema.

Parameters:

  • cocina_object (Cocina::Models::DRO)

Returns:

  • (Hash)

    Hash of DataCite attributes, conforming to the DataCite API Schema



13
14
15
# File 'lib/datacite/mapping/from_cocina/attributes.rb', line 13

def self.build(...)
  new(...).call
end

Instance Method Details

#callObject

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/datacite/mapping/from_cocina/attributes.rb', line 28

def call # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  {
    event: 'publish',
    url: description.purl,
    identifiers: Identifiers.build(identification:),
    titles: Titles.build(description:),
    publisher: { name: 'Stanford Digital Repository' }, # per DataCite schema
    publicationYear: publication_year,
    subjects: Subject.build(description:),
    dates: Date.build(cocina_object:),
    language: 'en',
    types: Types.build(description:),
    alternateIdentifiers: AlternateIdentifiers.build(description:),
    relatedIdentifiers: related_identifiers,
    rightsList: RightsList.build(access:),
    descriptions: Descriptions.build(description:),
    relatedItems: related_items,
    schemaVersion: 'http://datacite.org/schema/kernel-4'
  }.merge(ContributorAttributes.build(description:)).compact
end