Class: PDCMetadata::RelatedObject
- Inherits:
-
Object
- Object
- PDCMetadata::RelatedObject
- 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
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#related_identifier ⇒ Object
Returns the value of attribute related_identifier.
-
#related_identifier_type ⇒ Object
Returns the value of attribute related_identifier_type.
-
#relation_type ⇒ Object
Returns the value of attribute relation_type.
Class Method Summary collapse
Instance Method Summary collapse
- #compare_value ⇒ Object
-
#initialize(related_identifier:, related_identifier_type:, relation_type:) ⇒ RelatedObject
constructor
A new instance of RelatedObject.
- #valid? ⇒ Boolean
- #value ⇒ Object
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_type = @relation_type = relation_type # TODO: Older records have a different format. # When we migrate these, then this can be removed. unless .blank? || @related_identifier_type = ::Datacite::Mapping::RelatedIdentifierType.find do |obj| ::PDCMetadata.fuzzy_match(obj, ) 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
#errors ⇒ Object
Returns the value of attribute errors.
8 9 10 |
# File 'app/models/pdc_metadata/related_object.rb', line 8 def errors @errors end |
#related_identifier ⇒ Object
Returns the value of attribute related_identifier.
8 9 10 |
# File 'app/models/pdc_metadata/related_object.rb', line 8 def @related_identifier end |
#related_identifier_type ⇒ Object
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 end |
#relation_type ⇒ Object
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
.new_related_object(related_identifier, related_identifier_type, relation_type) ⇒ Object
51 52 53 |
# File 'app/models/pdc_metadata/related_object.rb', line 51 def self.(, , relation_type) RelatedObject.new(related_identifier:, related_identifier_type:, relation_type:) end |
Instance Method Details
#compare_value ⇒ Object
47 48 49 |
# File 'app/models/pdc_metadata/related_object.rb', line 47 def compare_value "#{} ('#{relation_type}' relation #{})" end |
#valid? ⇒ 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 = .present? && && valid_relation_type? return valid if valid if .blank? errors << "Related identifier is missing" else errors << "Related Identifier Type is missing or invalid for #{}" unless errors << "Relationship Type is missing or invalid for #{}" unless valid_relation_type? end false end |
#value ⇒ Object
43 44 45 |
# File 'app/models/pdc_metadata/related_object.rb', line 43 def value @related_identifier end |