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.
-
#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.
-
#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 |
#author? ⇒ Boolean
Does this contributor have a role that indicates they are an author?
59 60 61 |
# File 'lib/cocina_display/contributors/contributor.rb', line 59 def roles.any?(&:author?) end |
#conference? ⇒ Boolean
Is this contributor a conference?
47 48 49 |
# File 'lib/cocina_display/contributors/contributor.rb', line 47 def conference? cocina["type"] == "conference" end |
#display_name(with_date: false) ⇒ String?
The primary display name for the contributor as a string.
84 85 86 |
# File 'lib/cocina_display/contributors/contributor.rb', line 84 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.
91 92 93 |
# File 'lib/cocina_display/contributors/contributor.rb', line 91 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.
107 108 109 |
# File 'lib/cocina_display/contributors/contributor.rb', line 107 def forename names.map(&:forename_str).first.presence end |
#funder? ⇒ Boolean
Does this contributor have a role that indicates they are a funder?
71 72 73 |
# File 'lib/cocina_display/contributors/contributor.rb', line 71 def funder? roles.any?(&:funder?) end |
#identifiers ⇒ Array<Identifier>
Identifiers for the contributor.
29 30 31 |
# File 'lib/cocina_display/contributors/contributor.rb', line 29 def 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.
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/cocina_display/contributors/contributor.rb', line 121 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 |
#organization? ⇒ Boolean
Is this contributor an organization?
41 42 43 |
# File 'lib/cocina_display/contributors/contributor.rb', line 41 def organization? cocina["type"] == "organization" end |
#person? ⇒ Boolean
Is this contributor a human?
35 36 37 |
# File 'lib/cocina_display/contributors/contributor.rb', line 35 def person? cocina["type"] == "person" end |
#primary? ⇒ Boolean
Is this contributor marked as primary?
53 54 55 |
# File 'lib/cocina_display/contributors/contributor.rb', line 53 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.
98 99 100 101 102 |
# File 'lib/cocina_display/contributors/contributor.rb', line 98 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?
65 66 67 |
# File 'lib/cocina_display/contributors/contributor.rb', line 65 def publisher? roles.any?(&:publisher?) end |
#role? ⇒ Boolean
Does this contributor have any roles defined?
77 78 79 |
# File 'lib/cocina_display/contributors/contributor.rb', line 77 def role? roles.any? end |
#roles ⇒ Array<Hash>
All roles in the Cocina structured data.
136 137 138 |
# File 'lib/cocina_display/contributors/contributor.rb', line 136 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.
114 115 116 |
# File 'lib/cocina_display/contributors/contributor.rb', line 114 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 |