Class: PDCMetadata::RelatedObject

Inherits:
Object
  • Object
show all
Defined in:
app/models/pdc_metadata/related_object.rb

Overview

let(:related_identifier) { “www.biorxiv.org/content/10.1101/545517v1” } let(:related_identifier_type) { “arXiv” } let(:relation_type) { “IsCitedBy” }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(related_identifier:, related_identifier_type:, relation_type:) ⇒ RelatedObject

Returns a new instance of RelatedObject.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/pdc_metadata/related_object.rb', line 10

def initialize(related_identifier:, related_identifier_type:, relation_type:)
  @related_identifier = related_identifier
  @related_identifier_type = related_identifier_type
  @relation_type = relation_type

  # TODO: Older records have a different format.
  # When we migrate these, then this can be removed.
  unless related_identifier_type.blank? || valid_related_identifier_type?
    @related_identifier_type = ::Datacite::Mapping::RelatedIdentifierType.find do |obj|
      ::PDCMetadata.fuzzy_match(obj, related_identifier_type)
    end.value
  end
  unless relation_type.blank? || valid_relation_type?
    @relation_type = ::Datacite::Mapping::RelationType.find do |obj|
      ::PDCMetadata.fuzzy_match(obj, relation_type)
    end.value
  end

  @errors = []
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



8
9
10
# File 'app/models/pdc_metadata/related_object.rb', line 8

def errors
  @errors
end

Returns the value of attribute related_identifier.



8
9
10
# File 'app/models/pdc_metadata/related_object.rb', line 8

def related_identifier
  @related_identifier
end

Returns the value of attribute related_identifier_type.



8
9
10
# File 'app/models/pdc_metadata/related_object.rb', line 8

def related_identifier_type
  @related_identifier_type
end

#relation_typeObject

Returns the value of attribute relation_type.



8
9
10
# File 'app/models/pdc_metadata/related_object.rb', line 8

def relation_type
  @relation_type
end

Class Method Details



51
52
53
# File 'app/models/pdc_metadata/related_object.rb', line 51

def self.new_related_object(related_identifier, related_identifier_type, relation_type)
  RelatedObject.new(related_identifier:, related_identifier_type:, relation_type:)
end

Instance Method Details

#compare_valueObject



47
48
49
# File 'app/models/pdc_metadata/related_object.rb', line 47

def compare_value
  "#{related_identifier} ('#{relation_type}' relation #{related_identifier_type})"
end

#valid?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/pdc_metadata/related_object.rb', line 31

def valid?
  valid = related_identifier.present? && valid_related_identifier_type? && valid_relation_type?
  return valid if valid
  if related_identifier.blank?
    errors << "Related identifier is missing"
  else
    errors << "Related Identifier Type is missing or invalid for #{related_identifier}" unless valid_related_identifier_type?
    errors << "Relationship Type is missing or invalid for #{related_identifier}" unless valid_relation_type?
  end
  false
end

#valueObject



43
44
45
# File 'app/models/pdc_metadata/related_object.rb', line 43

def value
  @related_identifier
end