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
-
#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 display name for the contributor as a string.
-
#display_role ⇒ String
A string representation of the contributor’s roles, formatted for display.
-
#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?.
-
#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.
-
#to_s ⇒ String
String representation of the contributor, including name and role.
Constructor Details
#initialize(cocina) ⇒ Contributor
Initialize a Contributor object with Cocina structured data.
19 20 21 |
# File 'lib/cocina_display/contributors/contributor.rb', line 19 def initialize(cocina) @cocina = cocina end |
Instance Attribute Details
#cocina ⇒ Object (readonly)
Returns the value of attribute cocina.
15 16 17 |
# File 'lib/cocina_display/contributors/contributor.rb', line 15 def cocina @cocina end |
Instance Method Details
#author? ⇒ Boolean
Does this contributor have a role that indicates they are an author?
56 57 58 |
# File 'lib/cocina_display/contributors/contributor.rb', line 56 def roles.any?(&:author?) end |
#conference? ⇒ Boolean
Is this contributor a conference?
44 45 46 |
# File 'lib/cocina_display/contributors/contributor.rb', line 44 def conference? cocina["type"] == "conference" end |
#display_name(with_date: false) ⇒ String
The display name for the contributor as a string. Uses the first name if multiple names are present.
76 77 78 |
# File 'lib/cocina_display/contributors/contributor.rb', line 76 def display_name(with_date: false) names.map { |name| name.display_str(with_date: with_date) }.first end |
#display_role ⇒ String
A string representation of the contributor’s roles, formatted for display. If there are multiple roles, they are joined with commas.
83 84 85 |
# File 'lib/cocina_display/contributors/contributor.rb', line 83 def display_role roles.map(&:display_str).to_sentence end |
#names ⇒ Array<Name>
All names in the Cocina as Name objects.
89 90 91 |
# File 'lib/cocina_display/contributors/contributor.rb', line 89 def names @names ||= Array(cocina["name"]).map { |name| Name.new(name) } end |
#organization? ⇒ Boolean
Is this contributor an organization?
38 39 40 |
# File 'lib/cocina_display/contributors/contributor.rb', line 38 def organization? cocina["type"] == "organization" end |
#person? ⇒ Boolean
Is this contributor a human?
32 33 34 |
# File 'lib/cocina_display/contributors/contributor.rb', line 32 def person? cocina["type"] == "person" end |
#primary? ⇒ Boolean
Is this contributor marked as primary?
50 51 52 |
# File 'lib/cocina_display/contributors/contributor.rb', line 50 def primary? cocina["status"] == "primary" end |
#publisher? ⇒ Boolean
Does this contributor have a role that indicates they are a publisher?
62 63 64 |
# File 'lib/cocina_display/contributors/contributor.rb', line 62 def publisher? roles.any?(&:publisher?) end |
#role? ⇒ Boolean
Does this contributor have any roles defined?
68 69 70 |
# File 'lib/cocina_display/contributors/contributor.rb', line 68 def role? roles.any? end |
#roles ⇒ Array<Hash>
All roles in the Cocina structured data.
95 96 97 |
# File 'lib/cocina_display/contributors/contributor.rb', line 95 def roles @roles ||= Array(cocina["role"]).map { |role| Role.new(role) } end |
#to_s ⇒ String
String representation of the contributor, including name and role. Used for debugging and logging.
26 27 28 |
# File 'lib/cocina_display/contributors/contributor.rb', line 26 def to_s Utils.compact_and_join([display_name, display_role], delimiter: ": ") end |