Class: CocinaDisplay::Contributors::Contributor

Inherits:
Object
  • Object
show all
Defined in:
lib/cocina_display/contributors/contributor.rb

Overview

A contributor to a work, such as an author or publisher.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cocina) ⇒ Contributor

Initialize a Contributor object with Cocina structured data.

Parameters:

  • cocina (Hash)

    The Cocina structured data for the contributor.



11
12
13
# File 'lib/cocina_display/contributors/contributor.rb', line 11

def initialize(cocina)
  @cocina = cocina
end

Instance Attribute Details

#cocinaObject (readonly)

Returns the value of attribute cocina.



7
8
9
# File 'lib/cocina_display/contributors/contributor.rb', line 7

def cocina
  @cocina
end

Instance Method Details

#==(other) ⇒ Object

Support equality based on the underlying Cocina data.

Parameters:

  • other (Object)


23
24
25
# File 'lib/cocina_display/contributors/contributor.rb', line 23

def ==(other)
  other.is_a?(Contributor) && other.cocina == cocina
end

#affiliationsArray<CocinaDisplay::Contributors::Affiliation>

Affiliation data for the contributor.



136
137
138
# File 'lib/cocina_display/contributors/contributor.rb', line 136

def affiliations
  @affiliations ||= Array(cocina["affiliation"]).map { |affiliation| Affiliation.new(affiliation) }
end

#author?Boolean

Does this contributor have a role that indicates they are an author?

Returns:

  • (Boolean)


53
54
55
# File 'lib/cocina_display/contributors/contributor.rb', line 53

def author?
  roles.any?(&:author?)
end

#conference?Boolean

Is this contributor a conference?

Returns:

  • (Boolean)


41
42
43
# File 'lib/cocina_display/contributors/contributor.rb', line 41

def conference?
  cocina["type"] == "conference"
end

#display_name(with_date: false) ⇒ String?

The primary display name for the contributor as a string.

Parameters:

  • with_date (Boolean) (defaults to: false)

    Include life dates, if present

Returns:

  • (String, nil)


78
79
80
# File 'lib/cocina_display/contributors/contributor.rb', line 78

def display_name(with_date: false)
  primary_name&.to_s(with_date: with_date)
end

#display_names(with_date: false) ⇒ Array<String>

String renderings of all names for the contributor.

Parameters:

  • with_date (Boolean) (defaults to: false)

    Include life dates, if present

Returns:

  • (Array<String>)


85
86
87
# File 'lib/cocina_display/contributors/contributor.rb', line 85

def display_names(with_date: false)
  names.map { |name| name.to_s(with_date: with_date) }.compact_blank
end

#forenameString?

The forename for the contributor, if structured name info is available.

Returns:

  • (String, nil)

See Also:

  • Contributor::Name::forename_str


101
102
103
# File 'lib/cocina_display/contributors/contributor.rb', line 101

def forename
  names.map(&:forename_str).first.presence
end

#funder?Boolean

Does this contributor have a role that indicates they are a funder?

Returns:

  • (Boolean)


65
66
67
# File 'lib/cocina_display/contributors/contributor.rb', line 65

def funder?
  roles.any?(&:funder?)
end

#identifiersArray<Identifier>

Identifiers for the contributor.

Returns:



142
143
144
# File 'lib/cocina_display/contributors/contributor.rb', line 142

def identifiers
  @identifiers ||= Array(cocina["identifier"]).map { |id| Identifier.new(id) }
end

#namesArray<Name>

All names in the Cocina as Name objects. Flattens parallel values into separate Name objects.

Returns:



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/cocina_display/contributors/contributor.rb', line 115

def names
  @names ||= Array(cocina["name"]).flat_map do |name|
    (Array(name["parallelValue"]).presence || [name]).filter_map do |name_value|
      unless name_value.blank?
        Name.new(name_value).tap do |name_obj|
          name_obj.type ||= name["type"]
          name_obj.status ||= name["status"]
        end
      end
    end
  end
end

#orcidString?

ORCID URI for the contributor, if present.

Returns:

  • (String, nil)


155
156
157
# File 'lib/cocina_display/contributors/contributor.rb', line 155

def orcid
  orcid_identifier&.uri
end

#orcid?Boolean

Does this contributor have an ORCID?

Returns:

  • (Boolean)


148
149
150
# File 'lib/cocina_display/contributors/contributor.rb', line 148

def orcid?
  orcid_identifier.present?
end

#orcid_idString?

ORCID ID for the contributor, if present.

Examples:

0000-0003-4168-7198

Returns:

  • (String, nil)


162
163
164
# File 'lib/cocina_display/contributors/contributor.rb', line 162

def orcid_id
  orcid_identifier&.identifier
end

#organization?Boolean

Is this contributor an organization?

Returns:

  • (Boolean)


35
36
37
# File 'lib/cocina_display/contributors/contributor.rb', line 35

def organization?
  cocina["type"] == "organization"
end

#person?Boolean

Is this contributor a human?

Returns:

  • (Boolean)


29
30
31
# File 'lib/cocina_display/contributors/contributor.rb', line 29

def person?
  cocina["type"] == "person"
end

#primary?Boolean

Is this contributor marked as primary?

Returns:

  • (Boolean)


47
48
49
# File 'lib/cocina_display/contributors/contributor.rb', line 47

def primary?
  cocina["status"] == "primary"
end

#primary_nameContributor::Name?

A single primary name for the contributor. Prefers a name of type “display” or one marked primary.

Returns:

  • (Contributor::Name, nil)


92
93
94
95
96
# File 'lib/cocina_display/contributors/contributor.rb', line 92

def primary_name
  names.find { |name| name.type == "display" }.presence ||
    names.find(&:primary?).presence ||
    names.first
end

#publisher?Boolean

Does this contributor have a role that indicates they are a publisher?

Returns:

  • (Boolean)


59
60
61
# File 'lib/cocina_display/contributors/contributor.rb', line 59

def publisher?
  roles.any?(&:publisher?)
end

#role?Boolean

Does this contributor have any roles defined?

Returns:

  • (Boolean)


71
72
73
# File 'lib/cocina_display/contributors/contributor.rb', line 71

def role?
  roles.any?
end

#rolesArray<Hash>

All roles in the Cocina structured data.

Returns:

  • (Array<Hash>)


130
131
132
# File 'lib/cocina_display/contributors/contributor.rb', line 130

def roles
  @roles ||= Array(cocina["role"]).map { |role| Role.new(role) }
end

#surnameString?

The surname for the contributor, if structured name info is available.

Returns:

  • (String, nil)

See Also:

  • Contributor::Name::surname_str


108
109
110
# File 'lib/cocina_display/contributors/contributor.rb', line 108

def surname
  names.map(&:surname_str).first.presence
end

#to_sString?

String representation of the contributor, using display name with date.

Returns:

  • (String, nil)


17
18
19
# File 'lib/cocina_display/contributors/contributor.rb', line 17

def to_s
  display_name(with_date: true)
end