Class: CocinaDisplay::Contributors::Contributor
- Inherits:
-
Object
- Object
- CocinaDisplay::Contributors::Contributor
- Defined in:
- lib/cocina_display/contributors/contributor.rb
Overview
A contributor to a work, such as an author or publisher.
Instance Attribute Summary collapse
-
#cocina ⇒ Object
readonly
Returns the value of attribute cocina.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Support equality based on the underlying Cocina data.
-
#affiliations ⇒ Array<CocinaDisplay::Contributors::Affiliation>
Affiliation data for the contributor.
-
#author? ⇒ Boolean
Does this contributor have a role that indicates they are an author?.
-
#conference? ⇒ Boolean
Is this contributor a conference?.
-
#display_name(with_date: false) ⇒ String?
The primary display name for the contributor as a string.
-
#display_names(with_date: false) ⇒ Array<String>
String renderings of all names for the contributor.
-
#forename ⇒ String?
The forename for the contributor, if structured name info is available.
-
#funder? ⇒ Boolean
Does this contributor have a role that indicates they are a funder?.
-
#identifiers ⇒ Array<Identifier>
Identifiers for the contributor.
-
#initialize(cocina) ⇒ Contributor
constructor
Initialize a Contributor object with Cocina structured data.
-
#names ⇒ Array<Name>
All names in the Cocina as Name objects.
-
#orcid ⇒ String?
ORCID URI for the contributor, if present.
-
#orcid? ⇒ Boolean
Does this contributor have an ORCID?.
-
#orcid_id ⇒ String?
ORCID ID for the contributor, if present.
-
#organization? ⇒ Boolean
Is this contributor an organization?.
-
#person? ⇒ Boolean
Is this contributor a human?.
-
#primary? ⇒ Boolean
Is this contributor marked as primary?.
-
#primary_name ⇒ Contributor::Name?
A single primary name for the contributor.
-
#publisher? ⇒ Boolean
Does this contributor have a role that indicates they are a publisher?.
-
#role? ⇒ Boolean
Does this contributor have any roles defined?.
-
#roles ⇒ Array<Hash>
All roles in the Cocina structured data.
-
#surname ⇒ String?
The surname for the contributor, if structured name info is available.
-
#to_s ⇒ String?
String representation of the contributor, using display name with date.
Constructor Details
#initialize(cocina) ⇒ Contributor
Initialize a Contributor object with Cocina structured data.
11 12 13 |
# File 'lib/cocina_display/contributors/contributor.rb', line 11 def initialize(cocina) @cocina = cocina end |
Instance Attribute Details
#cocina ⇒ Object (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.
23 24 25 |
# File 'lib/cocina_display/contributors/contributor.rb', line 23 def ==(other) other.is_a?(Contributor) && other.cocina == cocina end |
#affiliations ⇒ Array<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?
53 54 55 |
# File 'lib/cocina_display/contributors/contributor.rb', line 53 def roles.any?(&:author?) end |
#conference? ⇒ Boolean
Is this contributor a conference?
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.
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.
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 |
#forename ⇒ String?
The forename for the contributor, if structured name info is available.
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?
65 66 67 |
# File 'lib/cocina_display/contributors/contributor.rb', line 65 def funder? roles.any?(&:funder?) end |
#identifiers ⇒ Array<Identifier>
Identifiers for the contributor.
142 143 144 |
# File 'lib/cocina_display/contributors/contributor.rb', line 142 def identifiers @identifiers ||= Array(cocina["identifier"]).map { |id| Identifier.new(id) } end |
#names ⇒ Array<Name>
All names in the Cocina as Name objects. Flattens parallel values into separate Name objects.
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 |
#orcid ⇒ String?
ORCID URI for the contributor, if present.
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?
148 149 150 |
# File 'lib/cocina_display/contributors/contributor.rb', line 148 def orcid? orcid_identifier.present? end |
#orcid_id ⇒ String?
ORCID ID for the contributor, if present.
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?
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?
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?
47 48 49 |
# File 'lib/cocina_display/contributors/contributor.rb', line 47 def primary? cocina["status"] == "primary" end |
#primary_name ⇒ Contributor::Name?
A single primary name for the contributor. Prefers a name of type “display” or one marked primary.
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?
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?
71 72 73 |
# File 'lib/cocina_display/contributors/contributor.rb', line 71 def role? roles.any? end |
#roles ⇒ Array<Hash>
All roles in the Cocina structured data.
130 131 132 |
# File 'lib/cocina_display/contributors/contributor.rb', line 130 def roles @roles ||= Array(cocina["role"]).map { |role| Role.new(role) } end |
#surname ⇒ String?
The surname for the contributor, if structured name info is available.
108 109 110 |
# File 'lib/cocina_display/contributors/contributor.rb', line 108 def surname names.map(&:surname_str).first.presence end |
#to_s ⇒ String?
String representation of the contributor, using display name with date.
17 18 19 |
# File 'lib/cocina_display/contributors/contributor.rb', line 17 def to_s display_name(with_date: true) end |