• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / 95ff1d10-5774-4415-8b66-ffb4f4f58024

pending completion
95ff1d10-5774-4415-8b66-ffb4f4f58024

Pull #725

circleci

Carolyn Cole
Updating manifest not to include the javascript for edit This seems to do nothing, so I am removing it
Pull Request #725: Updating manifest not to include the javascript for edit

1638 of 1684 relevant lines covered (97.27%)

102.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.44
/app/models/pdc_metadata/related_object.rb
1
# frozen_string_literal: true
2
# Class for storing a related object
3
module PDCMetadata
1✔
4
  # let(:related_identifier) { "https://www.biorxiv.org/content/10.1101/545517v1" }
5
  # let(:related_identifier_type) { "arXiv" }
6
  # let(:relation_type) { "IsCitedBy" }
7
  class RelatedObject
1✔
8
    attr_accessor :related_identifier, :related_identifier_type, :relation_type, :errors
1✔
9

10
    def initialize(related_identifier:, related_identifier_type:, relation_type:)
1✔
11
      @related_identifier = related_identifier
72✔
12
      @related_identifier_type = related_identifier_type
72✔
13
      @relation_type = relation_type
72✔
14
      @errors = []
72✔
15
    end
16

17
    def valid?
1✔
18
      valid = related_identifier.present? && valid_related_identifier_type? && valid_relation_type?
5✔
19
      return valid if valid
5✔
20
      if related_identifier.blank?
4✔
21
        errors << "Related identifier is missing"
1✔
22
      else
23
        errors << "Related Identifier Type is missing or invalid for #{related_identifier}" unless valid_related_identifier_type?
3✔
24
        errors << "Relationship Type is missing or invalid for #{related_identifier}" unless valid_relation_type?
3✔
25
      end
26
      false
4✔
27
    end
28

29
    def value
1✔
30
      @related_identifier
1✔
31
    end
32

33
    def compare_value
1✔
34
      "#{related_identifier} ('#{relation_type}' relation #{related_identifier_type})"
×
35
    end
36

37
    def self.new_related_object(related_identifier, related_identifier_type, relation_type)
1✔
38
      RelatedObject.new(related_identifier: related_identifier, related_identifier_type: related_identifier_type, relation_type: relation_type)
5✔
39
    end
40

41
    ##
42
    # Generate a list of valid options for the related_identifier_type field
43
    def self.related_identifier_type_options
1✔
44
      pairs = Datacite::Mapping::RelatedIdentifierType.to_a.map { |value| [value.key, value.value] }
20✔
45
      built = Hash[pairs]
1✔
46
      built.with_indifferent_access
1✔
47
    end
48

49
    ##
50
    # Generate a list of valid options for the relation_type field
51
    def self.relation_type_options
1✔
52
      pairs = Datacite::Mapping::RelationType.to_a.map { |value| [value.key, value.value] }
34✔
53
      built = Hash[pairs]
1✔
54
      built.with_indifferent_access
1✔
55
    end
56

57
    private
1✔
58

59
      def valid_related_identifier_type?
1✔
60
        @valid_related_identifier_type ||= valid_type_values.include?(related_identifier_type&.upcase)
7✔
61
      end
62

63
      def valid_relation_type?
1✔
64
        @valid_relation_type ||= valid_relationship_types.include?(relation_type&.upcase)
5✔
65
      end
66

67
      def valid_type_values
1✔
68
        @valid_type_values ||= Datacite::Mapping::RelatedIdentifierType.to_a.map(&:value).map(&:upcase)
6✔
69
      end
70

71
      def valid_relationship_types
1✔
72
        @valid_relationship_types ||= Datacite::Mapping::RelationType.to_a.map(&:value).map(&:upcase)
5✔
73
      end
74
  end
75
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc