Class: CocinaDisplay::ParallelValue

Inherits:
Object
  • Object
show all
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

Titles::TitleValue

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

Instance Method Summary collapse

Constructor Details

#initialize(cocina) ⇒ ParallelValue

Create a new ParallelValue object and set the appropriate role and type.

Parameters:

  • cocina (Hash)


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

#cocinaHash (readonly)

The underlying Cocina hash.

Returns:

  • (Hash)


10
11
12
# File 'lib/cocina_display/parallel_value.rb', line 10

def cocina
  @cocina
end

#roleString? (readonly)

What relationship does this value have to its siblings?

Returns:

  • (String, nil)


14
15
16
# File 'lib/cocina_display/parallel_value.rb', line 14

def role
  @role
end

#typeString?

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.

Returns:

  • (String, nil)


20
21
22
# File 'lib/cocina_display/parallel_value.rb', line 20

def type
  @type
end

Instance Method Details

#languageCocinaDisplay::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?

Returns:

  • (Boolean)


32
33
34
# File 'lib/cocina_display/parallel_value.rb', line 32

def main_value?
  role == "main"
end

#translated?Boolean

Is this value translated?

Returns:

  • (Boolean)


38
39
40
# File 'lib/cocina_display/parallel_value.rb', line 38

def translated?
  role == "translated"
end

#transliterated?Boolean

Is this value transliterated?

Returns:

  • (Boolean)


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)?

Returns:

  • (Boolean)


50
51
52
# File 'lib/cocina_display/parallel_value.rb', line 50

def type?
  type.present?
end