Class: CocinaDisplay::Parallel::Parallel
- Inherits:
-
Object
- Object
- CocinaDisplay::Parallel::Parallel
- Defined in:
- lib/cocina_display/parallel/parallel.rb
Overview
A base class for objects that have ParallelValues as children
Direct Known Subclasses
Contributors::Name, Notes::Note, Subjects::Subject, Titles::Title
Instance Attribute Summary collapse
-
#cocina ⇒ Hash
readonly
The underlying Cocina hash.
Instance Method Summary collapse
-
#has_translation? ⇒ Boolean
Is there a translated version of the object?.
-
#has_transliteration? ⇒ Boolean
Is there a transliterated version of the object?.
-
#has_vernacular? ⇒ Boolean
Is there a vernacular (non-English) version of the object?.
-
#initialize(cocina) ⇒ Parallel
constructor
Initialize a Parallel object with Cocina data.
-
#main_value ⇒ CocinaDisplay::ParallelValue?
The main value among the parallel values, according to these rules: 1.
-
#own_type ⇒ String?
The type of this object in the Cocina.
-
#own_typed? ⇒ Boolean
Does this object have a type defined in the Cocina?.
-
#parallel_values ⇒ Array<CocinaDisplay::ParallelValue>
Create ParallelValue objects for all parallelValue nodes, or just value if only one.
-
#primary? ⇒ Boolean
Is this object marked as primary?.
-
#status ⇒ String?
The status of the object relative to others, if any (e.g., “primary”).
-
#translated_value ⇒ CocinaDisplay::ParallelValue?
The translated value for this object, if any.
-
#transliterated_value ⇒ CocinaDisplay::ParallelValue?
The transliterated version of the object, if any.
-
#type ⇒ String?
The type, which can be inherited from the main parallel value if absent.
-
#typed? ⇒ Boolean
Does this object have a type?.
-
#vernacular_value ⇒ CocinaDisplay::ParallelValue?
The vernacular (non-English) version of the object, if any.
Constructor Details
#initialize(cocina) ⇒ Parallel
Initialize a Parallel object with Cocina data.
11 12 13 |
# File 'lib/cocina_display/parallel/parallel.rb', line 11 def initialize(cocina) @cocina = cocina end |
Instance Attribute Details
#cocina ⇒ Hash (readonly)
The underlying Cocina hash.
7 8 9 |
# File 'lib/cocina_display/parallel/parallel.rb', line 7 def cocina @cocina end |
Instance Method Details
#has_translation? ⇒ Boolean
Is there a translated version of the object?
70 71 72 |
# File 'lib/cocina_display/parallel/parallel.rb', line 70 def has_translation? translated_value.present? end |
#has_transliteration? ⇒ Boolean
Is there a transliterated version of the object?
82 83 84 |
# File 'lib/cocina_display/parallel/parallel.rb', line 82 def has_transliteration? transliterated_value.present? end |
#has_vernacular? ⇒ Boolean
Is there a vernacular (non-English) version of the object?
94 95 96 |
# File 'lib/cocina_display/parallel/parallel.rb', line 94 def has_vernacular? vernacular_value.present? end |
#main_value ⇒ CocinaDisplay::ParallelValue?
The main value among the parallel values, according to these rules:
-
If there’s a parallelValue with type “display”, use that.
-
If there’s a parallelValue marked as primary, use that.
-
If there’s a parallelValue in a vernacular (non-English) language, use that.
-
If there’s a parallelValue with a non-role type, like “alternative”, use that.
-
Otherwise, use the first parallelValue.
54 55 56 57 58 59 60 |
# File 'lib/cocina_display/parallel/parallel.rb', line 54 def main_value parallel_values.find(&:display?) || parallel_values.find(&:primary?) || parallel_values.find(&:vernacular?) || parallel_values.find(&:own_typed?) || parallel_values.first end |
#own_type ⇒ String?
The type of this object in the Cocina.
29 30 31 |
# File 'lib/cocina_display/parallel/parallel.rb', line 29 def own_type cocina["type"].presence end |
#own_typed? ⇒ Boolean
Does this object have a type defined in the Cocina?
35 36 37 |
# File 'lib/cocina_display/parallel/parallel.rb', line 35 def own_typed? own_type.present? end |
#parallel_values ⇒ Array<CocinaDisplay::ParallelValue>
Create ParallelValue objects for all parallelValue nodes, or just value if only one
41 42 43 44 45 |
# File 'lib/cocina_display/parallel/parallel.rb', line 41 def parallel_values @parallel_values ||= (Array(cocina["parallelValue"]).presence || [cocina]).map do |node| parallel_value_class.new(node, parent: self) end end |
#primary? ⇒ Boolean
Is this object marked as primary?
106 107 108 |
# File 'lib/cocina_display/parallel/parallel.rb', line 106 def primary? status == "primary" end |
#status ⇒ String?
The status of the object relative to others, if any (e.g., “primary”).
100 101 102 |
# File 'lib/cocina_display/parallel/parallel.rb', line 100 def status cocina["status"] end |
#translated_value ⇒ CocinaDisplay::ParallelValue?
The translated value for this object, if any.
64 65 66 |
# File 'lib/cocina_display/parallel/parallel.rb', line 64 def translated_value parallel_values.find(&:translated?) end |
#transliterated_value ⇒ CocinaDisplay::ParallelValue?
The transliterated version of the object, if any.
76 77 78 |
# File 'lib/cocina_display/parallel/parallel.rb', line 76 def transliterated_value parallel_values.find(&:transliterated?) end |
#type ⇒ String?
The type, which can be inherited from the main parallel value if absent.
17 18 19 |
# File 'lib/cocina_display/parallel/parallel.rb', line 17 def type own_type || main_value.own_type end |
#typed? ⇒ Boolean
Does this object have a type?
23 24 25 |
# File 'lib/cocina_display/parallel/parallel.rb', line 23 def typed? type.present? end |
#vernacular_value ⇒ CocinaDisplay::ParallelValue?
The vernacular (non-English) version of the object, if any.
88 89 90 |
# File 'lib/cocina_display/parallel/parallel.rb', line 88 def vernacular_value parallel_values.find(&:vernacular?) end |