Class: CocinaDisplay::Subjects::Subject
- Inherits:
-
Object
- Object
- CocinaDisplay::Subjects::Subject
- Defined in:
- lib/cocina_display/subjects/subject.rb
Overview
Base class for subjects in Cocina structured data.
Instance Attribute Summary collapse
-
#cocina ⇒ Object
readonly
Returns the value of attribute cocina.
Instance Method Summary collapse
-
#display_str ⇒ String
A string representation of the entire subject, concatenated for display.
-
#display_values ⇒ Array<String>
Array of display strings for each value in the subject.
-
#initialize(cocina) ⇒ Subject
constructor
Initialize a Subject object with Cocina structured data.
-
#subject_values ⇒ Array<SubjectValue>
Individual values composing this subject.
-
#type ⇒ String?
The top-level type of the subject.
Constructor Details
#initialize(cocina) ⇒ Subject
Initialize a Subject object with Cocina structured data.
12 13 14 |
# File 'lib/cocina_display/subjects/subject.rb', line 12 def initialize(cocina) @cocina = cocina end |
Instance Attribute Details
#cocina ⇒ Object (readonly)
Returns the value of attribute cocina.
8 9 10 |
# File 'lib/cocina_display/subjects/subject.rb', line 8 def cocina @cocina end |
Instance Method Details
#display_str ⇒ String
A string representation of the entire subject, concatenated for display.
32 33 34 |
# File 'lib/cocina_display/subjects/subject.rb', line 32 def display_str Utils.compact_and_join(display_values, delimiter: " > ") end |
#display_values ⇒ Array<String>
Array of display strings for each value in the subject. Used for search, where each value should be indexed separately.
26 27 28 |
# File 'lib/cocina_display/subjects/subject.rb', line 26 def display_values subject_values.map(&:display_str).compact_blank end |
#subject_values ⇒ Array<SubjectValue>
Individual values composing this subject. Can be multiple if the Cocina featured nested data. If no type was specified on a value, uses the top-level subject type.
40 41 42 43 44 45 46 |
# File 'lib/cocina_display/subjects/subject.rb', line 40 def subject_values @subject_values ||= Utils.flatten_nested_values(cocina, atomic_types: SubjectValue.atomic_types).map do |value| subject_value = SubjectValue.from_cocina(value) subject_value.type ||= type subject_value end end |
#type ⇒ String?
The top-level type of the subject.
19 20 21 |
# File 'lib/cocina_display/subjects/subject.rb', line 19 def type cocina["type"] end |