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.



19
20
21
# File 'lib/cocina_display/contributors/contributor.rb', line 19

def initialize(cocina)
  @cocina = cocina
end

Instance Attribute Details

#cocinaObject (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?

Returns:

  • (Boolean)


56
57
58
# File 'lib/cocina_display/contributors/contributor.rb', line 56

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

#conference?Boolean

Is this contributor a conference?

Returns:

  • (Boolean)


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.

Parameters:

  • with_date (Boolean) (defaults to: false)

    Include life dates, if present

Returns:

  • (String)


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_roleString

A string representation of the contributor’s roles, formatted for display. If there are multiple roles, they are joined with commas.

Returns:

  • (String)


83
84
85
# File 'lib/cocina_display/contributors/contributor.rb', line 83

def display_role
  roles.map(&:display_str).to_sentence
end

#namesArray<Name>

All names in the Cocina as Name objects.

Returns:



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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


68
69
70
# File 'lib/cocina_display/contributors/contributor.rb', line 68

def role?
  roles.any?
end

#rolesArray<Hash>

All roles in the Cocina structured data.

Returns:

  • (Array<Hash>)


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_sString

String representation of the contributor, including name and role. Used for debugging and logging.

Returns:

  • (String)


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