Class: CocinaDisplay::ParallelValue
- Inherits:
-
Object
- Object
- CocinaDisplay::ParallelValue
- Defined in:
- lib/cocina_display/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
Constant Summary collapse
- PARALLEL_TYPES =
Value types (in Cocina) that indicate the value is not the main value.
["parallel", "translated", "transliterated"]
Instance Attribute Summary collapse
-
#cocina ⇒ Hash
readonly
The underlying Cocina hash.
-
#role ⇒ String?
readonly
What relationship does this value have to its siblings?.
-
#type ⇒ String?
The type, which can be inherited from the parent object.
Instance Method Summary collapse
-
#initialize(cocina) ⇒ 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? ⇒ Boolean
Is this value the main value?.
-
#translated? ⇒ Boolean
Is this value translated?.
-
#transliterated? ⇒ Boolean
Is this value transliterated?.
-
#type? ⇒ Boolean
Does this value have a type (that isn’t one of PARALLEL_TYPES)?.
Constructor Details
#initialize(cocina) ⇒ ParallelValue
Create a new ParallelValue object and set the appropriate role and type.
24 25 26 27 28 |
# File 'lib/cocina_display/parallel_value.rb', line 24 def initialize(cocina) @cocina = cocina @role = PARALLEL_TYPES.find { |role| cocina["type"] == role } || "main" @type = cocina["type"] if main_value? end |
Instance Attribute Details
#cocina ⇒ Hash (readonly)
The underlying Cocina hash.
10 11 12 |
# File 'lib/cocina_display/parallel_value.rb', line 10 def cocina @cocina end |
#role ⇒ String? (readonly)
What relationship does this value have to its siblings?
14 15 16 |
# File 'lib/cocina_display/parallel_value.rb', line 14 def role @role end |
#type ⇒ String?
The type, which can be inherited from the parent object. Note that PARALLEL_TYPES are considered types in the Cocina, but we treat those separately as “roles” instead of a type.
20 21 22 |
# File 'lib/cocina_display/parallel_value.rb', line 20 def type @type end |
Instance Method Details
#language ⇒ CocinaDisplay::Languages::Language?
The language of the value, if specified.
56 57 58 |
# File 'lib/cocina_display/parallel_value.rb', line 56 def language @language ||= CocinaDisplay::Languages::Language.new(cocina["valueLanguage"]) if cocina["valueLanguage"].present? end |
#main_value? ⇒ Boolean
Is this value the main value?
32 33 34 |
# File 'lib/cocina_display/parallel_value.rb', line 32 def main_value? role == "main" end |
#translated? ⇒ Boolean
Is this value translated?
38 39 40 |
# File 'lib/cocina_display/parallel_value.rb', line 38 def translated? role == "translated" end |
#transliterated? ⇒ Boolean
Is this value transliterated?
44 45 46 |
# File 'lib/cocina_display/parallel_value.rb', line 44 def transliterated? role == "transliterated" || language&.transliterated? end |
#type? ⇒ Boolean
Does this value have a type (that isn’t one of PARALLEL_TYPES)?
50 51 52 |
# File 'lib/cocina_display/parallel_value.rb', line 50 def type? type.present? end |