Class: Sipity::Services::DoiCreationRequestMetadataGatherer

Inherits:
Object
  • Object
show all
Defined in:
app/services/sipity/services/doi_creation_request_metadata_gatherer.rb

Overview

Responsible for gathering the parameters for the DOI Minting request.

@note: I debated about where this information should reside. It made sense

to be part of the DoiCreationRequestJob, however this information is
relevant for more than the asynchronous job; It could be used as
validation, or display as we send that information on to remote
services. Ultimately, I found it easier to test this singular concern
as something separate from the job.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sip, options = {}) ⇒ DoiCreationRequestMetadataGatherer



17
18
19
20
21
# File 'app/services/sipity/services/doi_creation_request_metadata_gatherer.rb', line 17

def initialize(sip, options = {})
  @sip = sip
  # TODO: I don't want to craft a custom repository
  @repository = options.fetch(:repository) { default_repository }
end

Instance Attribute Details

#repositoryObject (readonly, private)

Returns the value of attribute repository



22
23
24
# File 'app/services/sipity/services/doi_creation_request_metadata_gatherer.rb', line 22

def repository
  @repository
end

#sipObject (readonly, private)

Returns the value of attribute sip



22
23
24
# File 'app/services/sipity/services/doi_creation_request_metadata_gatherer.rb', line 22

def sip
  @sip
end

Class Method Details

.call(sip:) ⇒ Object

A convenience method to codify the external API.



13
14
15
# File 'app/services/sipity/services/doi_creation_request_metadata_gatherer.rb', line 13

def self.call(sip:)
  new(sip).as_hash
end

Instance Method Details

#as_hashObject



25
26
27
28
29
30
31
32
33
# File 'app/services/sipity/services/doi_creation_request_metadata_gatherer.rb', line 25

def as_hash
  {
    '_target' => permanent_uri_for_sip,
    'datacite.title' => title,
    'datacite.creator' => creator,
    'datacite.publisher' => publisher,
    'datacite.publicationyear' => publication_year
  }
end

#creatorObject (private)



47
48
49
# File 'app/services/sipity/services/doi_creation_request_metadata_gatherer.rb', line 47

def creator
  @creator ||= repository.sip_collaborator_names_for(sip: sip, roles: 'author').join("; ")
end

#default_repositoryObject (private)



67
68
69
# File 'app/services/sipity/services/doi_creation_request_metadata_gatherer.rb', line 67

def default_repository
  Repository.new
end

#permanent_uri_for_sipObject (private)

The permanent URL in which we promise that you can always find this object.



39
40
41
# File 'app/services/sipity/services/doi_creation_request_metadata_gatherer.rb', line 39

def permanent_uri_for_sip
  Conversions::ConvertToPermanentUri.call(sip)
end

#publication_yearObject (private)



59
60
61
62
63
64
65
# File 'app/services/sipity/services/doi_creation_request_metadata_gatherer.rb', line 59

def publication_year
  @publication_year ||= begin
    repository.sip_attribute_values_for(
      sip: sip, key: Models::AdditionalAttribute::PUBLICATION_DATE_PREDICATE_NAME
    ).map { |publication_date| Conversions::ConvertToYear.call(publication_date).to_s }.join(", ")
  end
end

#publisherObject (private)



51
52
53
54
55
56
57
# File 'app/services/sipity/services/doi_creation_request_metadata_gatherer.rb', line 51

def publisher
  @publisher ||= begin
    repository.sip_attribute_values_for(
      sip: sip, key: Models::AdditionalAttribute::PUBLISHER_PREDICATE_NAME
    ).join("; ")
  end
end

#titleObject (private)



43
44
45
# File 'app/services/sipity/services/doi_creation_request_metadata_gatherer.rb', line 43

def title
  sip.title
end