Class: CocinaDisplay::Parallel::Parallel

Inherits:
Object
  • Object
show all
Defined in:
lib/cocina_display/parallel/parallel.rb

Overview

A base class for objects that have ParallelValues as children

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cocina) ⇒ Parallel

Initialize a Parallel object with Cocina data.

Parameters:

  • cocina (Hash)


11
12
13
# File 'lib/cocina_display/parallel/parallel.rb', line 11

def initialize(cocina)
  @cocina = cocina
end

Instance Attribute Details

#cocinaHash (readonly)

The underlying Cocina hash.

Returns:

  • (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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


94
95
96
# File 'lib/cocina_display/parallel/parallel.rb', line 94

def has_vernacular?
  vernacular_value.present?
end

#main_valueCocinaDisplay::ParallelValue?

The main value among the parallel values, according to these rules:

  1. If there’s a parallelValue with type “display”, use that.

  2. If there’s a parallelValue marked as primary, use that.

  3. If there’s a parallelValue in a vernacular (non-English) language, use that.

  4. If there’s a parallelValue with a non-role type, like “alternative”, use that.

  5. Otherwise, use the first parallelValue.

Returns:

  • (CocinaDisplay::ParallelValue, nil)


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

The type of this object in the Cocina.

Returns:

  • (String, nil)


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?

Returns:

  • (Boolean)


35
36
37
# File 'lib/cocina_display/parallel/parallel.rb', line 35

def own_typed?
  own_type.present?
end

#parallel_valuesArray<CocinaDisplay::ParallelValue>

Create ParallelValue objects for all parallelValue nodes, or just value if only one

Returns:

  • (Array<CocinaDisplay::ParallelValue>)


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?

Returns:

  • (Boolean)


106
107
108
# File 'lib/cocina_display/parallel/parallel.rb', line 106

def primary?
  status == "primary"
end

#statusString?

The status of the object relative to others, if any (e.g., “primary”).

Returns:

  • (String, nil)


100
101
102
# File 'lib/cocina_display/parallel/parallel.rb', line 100

def status
  cocina["status"]
end

#translated_valueCocinaDisplay::ParallelValue?

The translated value for this object, if any.

Returns:

  • (CocinaDisplay::ParallelValue, nil)


64
65
66
# File 'lib/cocina_display/parallel/parallel.rb', line 64

def translated_value
  parallel_values.find(&:translated?)
end

#transliterated_valueCocinaDisplay::ParallelValue?

The transliterated version of the object, if any.

Returns:

  • (CocinaDisplay::ParallelValue, nil)


76
77
78
# File 'lib/cocina_display/parallel/parallel.rb', line 76

def transliterated_value
  parallel_values.find(&:transliterated?)
end

#typeString?

The type, which can be inherited from the main parallel value if absent.

Returns:

  • (String, nil)


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?

Returns:

  • (Boolean)


23
24
25
# File 'lib/cocina_display/parallel/parallel.rb', line 23

def typed?
  type.present?
end

#vernacular_valueCocinaDisplay::ParallelValue?

The vernacular (non-English) version of the object, if any.

Returns:

  • (CocinaDisplay::ParallelValue, nil)


88
89
90
# File 'lib/cocina_display/parallel/parallel.rb', line 88

def vernacular_value
  parallel_values.find(&:vernacular?)
end