Class: CocinaDisplay::Contributors::Name

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

Overview

A name associated with a contributor.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cocina) ⇒ Name

Initialize a Name object with Cocina structured data.

Parameters:

  • cocina (Hash)

    The Cocina structured data for the name.



13
14
15
# File 'lib/cocina_display/contributors/name.rb', line 13

def initialize(cocina)
  @cocina = cocina
end

Instance Attribute Details

#cocinaObject (readonly)

Returns the value of attribute cocina.



9
10
11
# File 'lib/cocina_display/contributors/name.rb', line 9

def cocina
  @cocina
end

Instance Method Details

#display_str(with_date: false) ⇒ String

The display string for the name, optionally including life dates. Uses these values in order, if present:

  1. Unstructured value

  2. Any structured/parallel values marked as “display”

  3. Joined structured values, optionally with life dates

Examples:

no dates

name.display_name # => "King, Martin Luther, Jr."

with dates

name.display_name(with_date: true) # => "King, Martin Luther, Jr., 1929-1968"

Parameters:

  • with_date (Boolean) (defaults to: false)

    Include life dates, if present

Returns:

  • (String)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cocina_display/contributors/name.rb', line 28

def display_str(with_date: false)
  if cocina["value"].present?
    cocina["value"]
  elsif display_name_str.present?
    display_name_str
  elsif dates_str.present? && with_date
    Utils.compact_and_join([full_name_str, dates_str], delimiter: ", ")
  else
    full_name_str
  end
end