Class: CocinaDisplay::Subjects::SubjectValue
- Inherits:
-
Parallel::ParallelValue
- Object
- Parallel::ParallelValue
- CocinaDisplay::Subjects::SubjectValue
- Defined in:
- lib/cocina_display/subjects/subject_value.rb
Overview
A subject in Cocina structured data 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
-
#delimiter ⇒ String
Delimiter used to join the individual parts of the subject for display.
-
#flat_value ⇒ String
A string representation of the entire subject, concatenated for display.
-
#subject_parts ⇒ Array<SubjectPart>
Individual SubjectParts composing this subject.
-
#to_s ⇒ String
The value to use for display.
-
#values ⇒ Array<String>
Array of display strings for each part of the subject.
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
#delimiter ⇒ String
Delimiter used to join the individual parts of the subject for display.
27 28 29 |
# File 'lib/cocina_display/subjects/subject_value.rb', line 27 def delimiter " > " end |
#flat_value ⇒ String
A string representation of the entire subject, concatenated for display.
21 22 23 |
# File 'lib/cocina_display/subjects/subject_value.rb', line 21 def flat_value Utils.compact_and_join(values, delimiter: delimiter) end |
#subject_parts ⇒ Array<SubjectPart>
Individual SubjectParts composing this subject. Can be multiple if the Cocina featured structuredValues. All SubjectParts inherit the type of their parent Subject.
35 36 37 38 39 40 41 42 43 |
# File 'lib/cocina_display/subjects/subject_value.rb', line 35 def subject_parts @subject_parts ||= if SubjectPart.atomic_types.include?(type) SubjectPart.from_cocina(cocina, type: type) else Utils.flatten_nested_values(cocina, atomic_types: SubjectPart.atomic_types).flat_map do |value| SubjectPart.from_cocina(value, type: value["type"] || type) end end end |
#to_s ⇒ String
The value to use for display. Genre values are capitalized; other subject values are not.
15 16 17 |
# File 'lib/cocina_display/subjects/subject_value.rb', line 15 def to_s (type == "genre") ? flat_value&.upcase_first : flat_value end |
#values ⇒ Array<String>
Array of display strings for each part of the subject. Used for search, where each value should be indexed separately.
8 9 10 |
# File 'lib/cocina_display/subjects/subject_value.rb', line 8 def values subject_parts.map(&:to_s).compact_blank end |