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

pulibrary / pdc_describe / cace366a-ffad-45f1-9b60-678e607fa527

14 May 2024 02:21PM UTC coverage: 60.862% (-35.0%) from 95.908%
cace366a-ffad-45f1-9b60-678e607fa527

push

circleci

jrgriffiniii
wip

1 of 3 new or added lines in 2 files covered. (33.33%)

1194 existing lines in 57 files now uncovered.

2076 of 3411 relevant lines covered (60.86%)

22.71 hits per line

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

78.38
/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
182✔
12
      @related_identifier_type = related_identifier_type
182✔
13
      @relation_type = relation_type
182✔
14

15
      # TODO: Older records have a different format.
16
      # When we migrate these, then this can be removed.
17
      unless related_identifier_type.blank? || valid_related_identifier_type?
182✔
18
        @related_identifier_type = ::Datacite::Mapping::RelatedIdentifierType.find do |obj|
1✔
19
          ::PDCMetadata.fuzzy_match(obj, related_identifier_type)
2✔
20
        end.value
21
      end
22
      unless relation_type.blank? || valid_relation_type?
182✔
23
        @relation_type = ::Datacite::Mapping::RelationType.find do |obj|
2✔
24
          ::PDCMetadata.fuzzy_match(obj, relation_type)
2✔
25
        end.value
26
      end
27

28
      @errors = []
182✔
29
    end
30

31
    def valid?
1✔
32
      valid = related_identifier.present? && valid_related_identifier_type? && valid_relation_type?
46✔
33
      return valid if valid
46✔
UNCOV
34
      if related_identifier.blank?
×
UNCOV
35
        errors << "Related identifier is missing"
×
36
      else
UNCOV
37
        errors << "Related Identifier Type is missing or invalid for #{related_identifier}" unless valid_related_identifier_type?
×
UNCOV
38
        errors << "Relationship Type is missing or invalid for #{related_identifier}" unless valid_relation_type?
×
39
      end
UNCOV
40
      false
×
41
    end
42

43
    def value
1✔
UNCOV
44
      @related_identifier
×
45
    end
46

47
    def compare_value
1✔
UNCOV
48
      "#{related_identifier} ('#{relation_type}' relation #{related_identifier_type})"
×
49
    end
50

51
    def self.new_related_object(related_identifier, related_identifier_type, relation_type)
1✔
UNCOV
52
      RelatedObject.new(related_identifier:, related_identifier_type:, relation_type:)
×
53
    end
54

55
    private
1✔
56

57
      def valid_related_identifier_type?
1✔
58
        @valid_related_identifier_type ||= valid_type_values.include?(related_identifier_type)
228✔
59
      end
60

61
      def valid_relation_type?
1✔
62
        @valid_relation_type ||= valid_relationship_types.include?(relation_type)
228✔
63
      end
64

65
      def valid_type_values
1✔
66
        @valid_type_values ||= Datacite::Mapping::RelatedIdentifierType.map(&:value)
182✔
67
      end
68

69
      def valid_relationship_types
1✔
70
        @valid_relationship_types ||= Datacite::Mapping::RelationType.map(&:value)
182✔
71
      end
72
  end
73
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