Class: CocinaDisplay::Contributors::NameValue

Inherits:
Parallel::ParallelValue show all
Defined in:
lib/cocina_display/contributors/name_value.rb

Overview

A name associated with a contributor in a single language/script.

Constant Summary

Constants inherited from Parallel::ParallelValue

Parallel::ParallelValue::PARALLEL_TYPES

Instance Attribute Summary

Attributes inherited from Parallel::ParallelValue

#cocina, #parent, #role

Instance Method Summary collapse

Methods inherited from Parallel::ParallelValue

#display?, #initialize, #language, #main_value, #own_type, #own_typed?, #primary?, #siblings, #status, #translated?, #transliterated?, #type, #typed?, #vernacular?

Constructor Details

This class inherits a constructor from CocinaDisplay::Parallel::ParallelValue

Instance Method Details

#dates_strString

Flatten all life and activity dates into a comma-delimited string.

Returns:

  • (String)


58
59
60
# File 'lib/cocina_display/contributors/name_value.rb', line 58

def dates_str
  Utils.compact_and_join(Array(name_values["life dates"]) + Array(name_values["activity dates"]), delimiter: ", ")
end

#forename_strString

Flatten all forename values and ordinals into a whitespace-delimited string.

Returns:

  • (String)


46
47
48
# File 'lib/cocina_display/contributors/name_value.rb', line 46

def forename_str
  Utils.compact_and_join(Array(name_values["forename"]) + Array(name_values["ordinal"]), delimiter: " ")
end

#full_name_strString

The full name as a string, combining all name components and terms of address.

Returns:

  • (String)


26
27
28
# File 'lib/cocina_display/contributors/name_value.rb', line 26

def full_name_str
  Utils.compact_and_join(name_components.push(terms_of_address_str), delimiter: ", ")
end

#name_componentsArray<String>

List of all name components. If any of forename, surname, or term of address are present, those are used. Otherwise, fall back to any names explicitly marked as “name” or untyped.

Returns:

  • (Array<String>)


34
35
36
# File 'lib/cocina_display/contributors/name_value.rb', line 34

def name_components
  [surname_str, forename_str].compact_blank.presence || Array(name_values["name"])
end

#surname_strString

Flatten all surname values into a whitespace-delimited string.

Returns:

  • (String)


52
53
54
# File 'lib/cocina_display/contributors/name_value.rb', line 52

def surname_str
  Utils.compact_and_join(Array(name_values["surname"]), delimiter: " ")
end

#terms_of_address_strString

Flatten all terms of address into a comma-delimited string.

Returns:

  • (String)


40
41
42
# File 'lib/cocina_display/contributors/name_value.rb', line 40

def terms_of_address_str
  Utils.compact_and_join(Array(name_values["term of address"]), delimiter: ", ")
end

#to_s(with_date: false) ⇒ String

The display string for the name, optionally including life dates.

Examples:

no dates

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

with dates

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

Parameters:

  • with_date (Boolean) (defaults to: false)

    Include life dates, if present

Returns:

  • (String)


14
15
16
17
18
19
20
21
22
# File 'lib/cocina_display/contributors/name_value.rb', line 14

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