Class: CocinaDisplay::Contributors::Name
- Inherits:
-
Object
- Object
- CocinaDisplay::Contributors::Name
- Defined in:
- lib/cocina_display/contributors/name.rb
Overview
A name associated with a contributor.
Instance Attribute Summary collapse
-
#cocina ⇒ Hash
readonly
The underlying Cocina structured data for the name.
-
#status ⇒ String?
The status of the name, if any (e.g., “primary”).
-
#type ⇒ String?
The type of name, if any (e.g., “personal”, “corporate”, etc.).
Instance Method Summary collapse
-
#dates_str ⇒ String
Flatten all life and activity dates into a comma-delimited string.
-
#forename_str ⇒ String
Flatten all forename values and ordinals into a whitespace-delimited string.
-
#full_name_str ⇒ String
The full name as a string, combining all name components and terms of address.
-
#initialize(cocina) ⇒ Name
constructor
Initialize a Name object with Cocina structured data.
-
#name_components ⇒ Array<String>
List of all name components.
-
#primary? ⇒ Boolean
Is this a primary name for the contributor?.
-
#surname_str ⇒ String
Flatten all surname values into a whitespace-delimited string.
-
#terms_of_address_str ⇒ String
Flatten all terms of address into a comma-delimited string.
-
#to_s(with_date: false) ⇒ String
The display string for the name, optionally including life dates.
Constructor Details
#initialize(cocina) ⇒ Name
Initialize a Name object with Cocina structured data.
21 22 23 24 25 |
# File 'lib/cocina_display/contributors/name.rb', line 21 def initialize(cocina) @cocina = cocina @type = cocina["type"] @status = cocina["status"] end |
Instance Attribute Details
#cocina ⇒ Hash (readonly)
The underlying Cocina structured data for the name.
9 10 11 |
# File 'lib/cocina_display/contributors/name.rb', line 9 def cocina @cocina end |
#status ⇒ String?
The status of the name, if any (e.g., “primary”).
17 18 19 |
# File 'lib/cocina_display/contributors/name.rb', line 17 def status @status end |
#type ⇒ String?
The type of name, if any (e.g., “personal”, “corporate”, etc.).
13 14 15 |
# File 'lib/cocina_display/contributors/name.rb', line 13 def type @type end |
Instance Method Details
#dates_str ⇒ String
Flatten all life and activity dates into a comma-delimited string.
78 79 80 |
# File 'lib/cocina_display/contributors/name.rb', line 78 def dates_str Utils.compact_and_join(Array(name_values["life dates"]) + Array(name_values["activity dates"]), delimiter: ", ") end |
#forename_str ⇒ String
Flatten all forename values and ordinals into a whitespace-delimited string.
66 67 68 |
# File 'lib/cocina_display/contributors/name.rb', line 66 def forename_str Utils.compact_and_join(Array(name_values["forename"]) + Array(name_values["ordinal"]), delimiter: " ") end |
#full_name_str ⇒ String
The full name as a string, combining all name components and terms of address.
46 47 48 |
# File 'lib/cocina_display/contributors/name.rb', line 46 def full_name_str Utils.compact_and_join(name_components.push(terms_of_address_str), delimiter: ", ") end |
#name_components ⇒ Array<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.
54 55 56 |
# File 'lib/cocina_display/contributors/name.rb', line 54 def name_components [surname_str, forename_str].compact_blank.presence || Array(name_values["name"]) end |
#primary? ⇒ Boolean
Is this a primary name for the contributor?
84 85 86 |
# File 'lib/cocina_display/contributors/name.rb', line 84 def primary? status == "primary" end |
#surname_str ⇒ String
Flatten all surname values into a whitespace-delimited string.
72 73 74 |
# File 'lib/cocina_display/contributors/name.rb', line 72 def surname_str Utils.compact_and_join(Array(name_values["surname"]), delimiter: " ") end |
#terms_of_address_str ⇒ String
Flatten all terms of address into a comma-delimited string.
60 61 62 |
# File 'lib/cocina_display/contributors/name.rb', line 60 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.
34 35 36 37 38 39 40 41 42 |
# File 'lib/cocina_display/contributors/name.rb', line 34 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 end end |