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

pulibrary / pdc_describe / 9091a1ae-29be-458c-984a-339d213919c4

12 Dec 2024 07:41PM UTC coverage: 26.434% (-69.7%) from 96.113%
9091a1ae-29be-458c-984a-339d213919c4

Pull #2000

circleci

jrgriffiniii
Removing integration with ActiveStorage
Pull Request #2000: Bump actionpack from 7.2.1.1 to 7.2.2.1

945 of 3575 relevant lines covered (26.43%)

0.35 hits per line

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

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

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

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

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

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

54
    def orcid_url
1✔
55
      identifier&.orcid_url
×
56
    end
57

58
    def orcid
1✔
59
      identifier&.orcid
×
60
    end
61

62
    def ror_url
1✔
63
      identifier&.ror_url
×
64
    end
65

66
    def ror
1✔
67
      identifier&.ror
×
68
    end
69

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

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

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

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

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

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

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