Class: CocinaDisplay::Subjects::SubjectValue

Inherits:
Parallel::ParallelValue show all
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

#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

#delimiterString

Delimiter used to join the individual parts of the subject for display.

Returns:

  • (String)


27
28
29
# File 'lib/cocina_display/subjects/subject_value.rb', line 27

def delimiter
  " > "
end

#flat_valueString

A string representation of the entire subject, concatenated for display.

Returns:

  • (String)


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_partsArray<SubjectPart>

Individual SubjectParts composing this subject. Can be multiple if the Cocina featured structuredValues. All SubjectParts inherit the type of their parent Subject.

Returns:



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_sString

The value to use for display. Genre values are capitalized; other subject values are not.

Returns:

  • (String)


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

#valuesArray<String>

Array of display strings for each part of the subject. Used for search, where each value should be indexed separately.

Returns:

  • (Array<String>)


8
9
10
# File 'lib/cocina_display/subjects/subject_value.rb', line 8

def values
  subject_parts.map(&:to_s).compact_blank
end