Class: CocinaDisplay::Parallel::ParallelValue
- Inherits:
-
Object
- Object
- CocinaDisplay::Parallel::ParallelValue
- Defined in:
- lib/cocina_display/parallel/parallel_value.rb
Overview
A base class for values representing one of several siblings describing the same thing in different languages or scripts.
Direct Known Subclasses
Contributors::NameValue, Notes::NoteValue, Subjects::SubjectValue, Titles::TitleValue
Constant Summary collapse
- PARALLEL_TYPES =
Value types (in Cocina) that are used to indicate sibling relationships.
["parallel", "translated", "translation", "transliterated", "transliteration", "display"].freeze
Instance Attribute Summary collapse
-
#cocina ⇒ Hash
readonly
The underlying Cocina hash.
-
#parent ⇒ Object
readonly
The parent object that contains this value and its potential siblings.
-
#role ⇒ String?
readonly
What relationship does this value have to its siblings?.
Instance Method Summary collapse
-
#display? ⇒ Boolean
Is this value explicitly intended for display?.
-
#initialize(cocina, parent:) ⇒ ParallelValue
constructor
Create a new ParallelValue object and set the appropriate role and type.
-
#language ⇒ CocinaDisplay::Languages::Language?
The language of the value, if specified.
-
#main_value ⇒ CocinaDisplay::ParallelValue
The main value among the siblings, which could be this value.
-
#own_type ⇒ String?
The type of this object in the Cocina, unless it’s one of PARALLEL_TYPES.
-
#own_typed? ⇒ Boolean
Does this value have a type in the Cocina?.
-
#primary? ⇒ Boolean
Is this value marked as primary?.
-
#siblings ⇒ Array<CocinaDisplay::ParallelValue>
Sibling values with the same parent.
-
#status ⇒ String?
The status of the value relative to siblings, if any (e.g., “primary”).
-
#translated? ⇒ Boolean
Is this value translated? True if the role is “translated” or “translation”, or if there is a parallel vernacular value but this one is in English.
-
#transliterated? ⇒ Boolean
Is this value transliterated?.
-
#type ⇒ String?
The type, which can be inherited from the main sibling or parent object.
-
#typed? ⇒ Boolean
Does this value have a type?.
-
#vernacular? ⇒ Boolean
Is this value in a native (non-English) language?.
Constructor Details
#initialize(cocina, parent:) ⇒ ParallelValue
Create a new ParallelValue object and set the appropriate role and type.
28 29 30 31 32 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 28 def initialize(cocina, parent:) @cocina = cocina @parent = parent @role = PARALLEL_TYPES.find { |role| cocina["type"] == role } end |
Instance Attribute Details
#cocina ⇒ Hash (readonly)
The underlying Cocina hash.
11 12 13 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 11 def cocina @cocina end |
#parent ⇒ Object (readonly)
The parent object that contains this value and its potential siblings.
15 16 17 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 15 def parent @parent end |
#role ⇒ String? (readonly)
What relationship does this value have to its siblings?
19 20 21 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 19 def role @role end |
Instance Method Details
#display? ⇒ Boolean
Is this value explicitly intended for display?
42 43 44 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 42 def display? role == "display" end |
#language ⇒ CocinaDisplay::Languages::Language?
The language of the value, if specified.
107 108 109 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 107 def language @language ||= CocinaDisplay::Languages::Language.new(cocina["valueLanguage"]) if cocina["valueLanguage"].present? end |
#main_value ⇒ CocinaDisplay::ParallelValue
The main value among the siblings, which could be this value.
23 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 23 delegate :main_value, to: :parent |
#own_type ⇒ String?
PARALLEL_TYPES are types in Cocina, but we treat them as “roles”.
The type of this object in the Cocina, unless it’s one of PARALLEL_TYPES.
75 76 77 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 75 def own_type cocina["type"] unless PARALLEL_TYPES.include?(cocina["type"]) end |
#own_typed? ⇒ Boolean
PARALLEL_TYPES are ignored since they indicate role, not type.
Does this value have a type in the Cocina?
88 89 90 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 88 def own_typed? own_type.present? end |
#primary? ⇒ Boolean
Is this value marked as primary?
101 102 103 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 101 def primary? status == "primary" end |
#siblings ⇒ Array<CocinaDisplay::ParallelValue>
Sibling values with the same parent.
36 37 38 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 36 def siblings parent.parallel_values.reject { |value| value == self } end |
#status ⇒ String?
We treat this the same as “role”.
The status of the value relative to siblings, if any (e.g., “primary”).
95 96 97 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 95 def status cocina["status"] end |
#translated? ⇒ Boolean
Is this value translated? True if the role is “translated” or “translation”, or if there is a parallel vernacular value but this one is in English.
56 57 58 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 56 def translated? role == "translated" || role == "translation" || (siblings.any?(&:vernacular?) && language&.english?) end |
#transliterated? ⇒ Boolean
Is this value transliterated?
62 63 64 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 62 def transliterated? role == "transliterated" || role == "transliteration" || language&.transliterated? end |
#type ⇒ String?
The type, which can be inherited from the main sibling or parent object.
68 69 70 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 68 def type own_type || main_value.own_type || parent.own_type end |
#typed? ⇒ Boolean
Does this value have a type?
81 82 83 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 81 def typed? type.present? end |
#vernacular? ⇒ Boolean
Is this value in a native (non-English) language?
48 49 50 |
# File 'lib/cocina_display/parallel/parallel_value.rb', line 48 def vernacular? language.present? && !language.english? end |