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

pulibrary / pdc_describe / 4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

07 Apr 2025 06:36PM UTC coverage: 1.283% (-94.6%) from 95.862%
4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

Pull #1994

circleci

hectorcorrea
Switched to use the autocomplete that we aleady use for ROR. Integrated it with the existing logic for creators
Pull Request #1994: Started adding auto complete to contributors

0 of 46 new or added lines in 2 files covered. (0.0%)

4806 existing lines in 74 files now uncovered.

65 of 5065 relevant lines covered (1.28%)

0.01 hits per line

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

0.0
/app/models/pdc_metadata/creator.rb
1
# frozen_string_literal: true
2
# Class for storing a creator in our local representation
UNCOV
3
module PDCMetadata
×
4
  # value: "Miller, Elizabeth"
5
  # name_type: "Personal"
6
  # given_name: "Elizabeth"
7
  # family_name: "Miller"
UNCOV
8
  class Creator
×
UNCOV
9
    attr_accessor :value, :name_type, :given_name, :family_name, :identifier, :affiliations, :sequence, :type
×
10

UNCOV
11
    class << self
×
UNCOV
12
      def from_hash(creator)
×
UNCOV
13
        given_name = creator["given_name"]
×
UNCOV
14
        family_name = creator["family_name"]
×
UNCOV
15
        orcid = creator.dig("identifier", "scheme") == "ORCID" ? creator.dig("identifier", "value") : nil
×
UNCOV
16
        sequence = (creator["sequence"] || "").to_i
×
UNCOV
17
        pdc_creator = PDCMetadata::Creator.new_person(given_name, family_name, orcid, sequence)
×
UNCOV
18
        pdc_creator.affiliations = (creator["affiliations"])&.map do |affiliation|
×
UNCOV
19
          PDCMetadata::Affiliation.new(value: affiliation["value"], identifier: affiliation["identifier"],
×
UNCOV
20
                                       scheme: affiliation["scheme"], scheme_uri: affiliation["scheme_uri"])
×
UNCOV
21
        end
×
UNCOV
22
        pdc_creator
×
UNCOV
23
      end
×
24

UNCOV
25
      def individual_contributor_from_hash(contributor)
×
UNCOV
26
        given_name = contributor["given_name"]
×
UNCOV
27
        family_name = contributor["family_name"]
×
UNCOV
28
        orcid = contributor.dig("identifier", "scheme") == "ORCID" ? contributor.dig("identifier", "value") : nil
×
UNCOV
29
        sequence = (contributor["sequence"] || "").to_i
×
UNCOV
30
        type = contributor["type"]
×
UNCOV
31
        PDCMetadata::Creator.new_individual_contributor(given_name, family_name, orcid, type, sequence)
×
UNCOV
32
      end
×
33

UNCOV
34
      def organizational_contributor_from_hash(contributor)
×
UNCOV
35
        value = contributor["value"]
×
UNCOV
36
        ror = contributor.dig("identifier", "scheme") == "ROR" ? contributor.dig("identifier", "value") : nil
×
UNCOV
37
        type = contributor["type"]
×
UNCOV
38
        PDCMetadata::Creator.new_organizational_contributor(value, ror, type)
×
UNCOV
39
      end
×
UNCOV
40
    end
×
41

42
    # rubocop:disable Metrics/ParameterLists
UNCOV
43
    def initialize(value: nil, name_type: nil, given_name: nil, family_name: nil, identifier: nil, sequence: 0, affiliations: [])
×
UNCOV
44
      @value = value&.strip
×
UNCOV
45
      @name_type = name_type&.strip
×
UNCOV
46
      @given_name = given_name&.strip
×
UNCOV
47
      @family_name = family_name&.strip
×
UNCOV
48
      @identifier = identifier&.strip
×
UNCOV
49
      @affiliations = affiliations
×
UNCOV
50
      @sequence = sequence
×
UNCOV
51
    end
×
52
    # rubocop:enable Metrics/ParameterLists
53

UNCOV
54
    def orcid_url
×
UNCOV
55
      identifier&.orcid_url
×
UNCOV
56
    end
×
57

UNCOV
58
    def orcid
×
UNCOV
59
      identifier&.orcid
×
UNCOV
60
    end
×
61

UNCOV
62
    def ror_url
×
63
      identifier&.ror_url
×
UNCOV
64
    end
×
65

UNCOV
66
    def ror
×
UNCOV
67
      identifier&.ror
×
UNCOV
68
    end
×
69

UNCOV
70
    def compare_value
×
UNCOV
71
      "#{value} | #{sequence} | #{type} | #{affiliations.map(&:compare_value).join(',')} | #{orcid_url}"
×
UNCOV
72
    end
×
73

UNCOV
74
    def affiliation
×
UNCOV
75
      return "" if affiliations.empty?
×
UNCOV
76
      affiliations.first.value
×
UNCOV
77
    end
×
78

UNCOV
79
    def affiliation_ror
×
UNCOV
80
      ror_affiliations = affiliations.select { |affiliation| affiliation.scheme == "ROR" }
×
UNCOV
81
      return "" if ror_affiliations.empty?
×
UNCOV
82
      ror_affiliations.first.identifier
×
UNCOV
83
    end
×
84

UNCOV
85
    def self.new_person(given_name, family_name, orcid_id = nil, sequence = 0, ror: nil, affiliation: nil)
×
UNCOV
86
      full_name = "#{family_name&.strip}, #{given_name&.strip}"
×
UNCOV
87
      creator = Creator.new(value: full_name, name_type: "Personal", given_name:, family_name:, sequence:)
×
UNCOV
88
      if orcid_id.present?
×
UNCOV
89
        creator.identifier = NameIdentifier.new_orcid(orcid_id.strip)
×
UNCOV
90
      end
×
UNCOV
91
      if affiliation.present? || ror.present?
×
UNCOV
92
        creator.affiliations << Affiliation.new_affiliation(value: affiliation, ror:)
×
UNCOV
93
      end
×
UNCOV
94
      creator
×
UNCOV
95
    end
×
96

UNCOV
97
    def self.new_individual_contributor(given_name, family_name, orcid_id, type, sequence)
×
UNCOV
98
      contributor = new_person(given_name, family_name, orcid_id, sequence)
×
UNCOV
99
      contributor.type = type
×
UNCOV
100
      contributor
×
UNCOV
101
    end
×
102

UNCOV
103
    def self.new_organization(value, ror = nil)
×
UNCOV
104
      creator = Creator.new(value:, name_type: "Organizational")
×
UNCOV
105
      if ror.present?
×
UNCOV
106
        creator.identifier = NameIdentifier.new_ror(ror.strip)
×
UNCOV
107
      end
×
UNCOV
108
      creator
×
UNCOV
109
    end
×
110

UNCOV
111
    def self.new_organizational_contributor(value, ror, type)
×
UNCOV
112
      contributor = new_organization(value, ror)
×
UNCOV
113
      contributor.type = type
×
UNCOV
114
      contributor
×
UNCOV
115
    end
×
UNCOV
116
  end
×
UNCOV
117
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