• 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

77.46
/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"]
1,232✔
14
        family_name = creator["family_name"]
1,232✔
15
        orcid = creator.dig("identifier", "scheme") == "ORCID" ? creator.dig("identifier", "value") : nil
1,232✔
16
        sequence = (creator["sequence"] || "").to_i
1,232✔
17
        pdc_creator = PDCMetadata::Creator.new_person(given_name, family_name, orcid, sequence)
1,232✔
18
        pdc_creator.affiliations = (creator["affiliations"])&.map do |affiliation|
1,232✔
19
          PDCMetadata::Affiliation.new(value: affiliation["value"], identifier: affiliation["identifier"],
7✔
20
                                       scheme: affiliation["scheme"], scheme_uri: affiliation["scheme_uri"])
21
        end
22
        pdc_creator
1,232✔
23
      end
24

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

34
      def organizational_contributor_from_hash(contributor)
1✔
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)
×
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
1,396✔
45
      @name_type = name_type&.strip
1,396✔
46
      @given_name = given_name&.strip
1,396✔
47
      @family_name = family_name&.strip
1,396✔
48
      @identifier = identifier&.strip
1,396✔
49
      @affiliations = affiliations
1,396✔
50
      @sequence = sequence
1,396✔
51
    end
52
    # rubocop:enable Metrics/ParameterLists
53

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

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

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

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

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

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

79
    def affiliation_ror
1✔
80
      ror_affiliations = affiliations.select { |affiliation| affiliation.scheme == "ROR" }
188✔
81
      return "" if ror_affiliations.empty?
188✔
UNCOV
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}"
1,396✔
87
      creator = Creator.new(value: full_name, name_type: "Personal", given_name:, family_name:, sequence:)
1,396✔
88
      if orcid_id.present?
1,396✔
89
        creator.identifier = NameIdentifier.new_orcid(orcid_id.strip)
2✔
90
      end
91
      if affiliation.present? || ror.present?
1,396✔
UNCOV
92
        creator.affiliations << Affiliation.new_affiliation(value: affiliation, ror:)
×
93
      end
94
      creator
1,396✔
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)
47✔
99
      contributor.type = type
47✔
100
      contributor
47✔
101
    end
102

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

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