Class: CocinaDisplay::Contributors::NameValue
- Inherits:
-
Parallel::ParallelValue
- Object
- Parallel::ParallelValue
- CocinaDisplay::Contributors::NameValue
- 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
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.
-
#name_components ⇒ Array<String>
List of all name components.
-
#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.
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_str ⇒ String
Flatten all life and activity dates into a comma-delimited 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_str ⇒ String
Flatten all forename values and ordinals into a whitespace-delimited 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_str ⇒ String
The full name as a string, combining all name components and terms of address.
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_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.
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_str ⇒ String
Flatten all surname values into a whitespace-delimited 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_str ⇒ String
Flatten all terms of address into a comma-delimited 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.
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 |