Class: CocinaDisplay::Titles::Title
- Inherits:
-
Object
- Object
- CocinaDisplay::Titles::Title
- Defined in:
- lib/cocina_display/titles/title.rb
Overview
A Title represented by one or more TitleValues in various languages/scripts.
Instance Attribute Summary collapse
-
#cocina ⇒ Object
readonly
The underlying Cocina hash.
-
#status ⇒ String?
Status of the title, e.g.
Instance Method Summary collapse
-
#has_translation? ⇒ Boolean
Is there a translated version of the title?.
-
#has_transliteration? ⇒ Boolean
Is there a transliterated version of the title?.
-
#initialize(cocina, part_label: nil, part_numbers: nil) ⇒ Title
constructor
Create a new Title object.
-
#label ⇒ String
Label used when displaying the title.
-
#main_value ⇒ TitleValue
The main value of the title, ignoring parallel values if any.
-
#parallel_values ⇒ Array<TitleValue>
All values except the main value.
-
#primary? ⇒ Boolean
Is this marked as a primary title?.
-
#title_values ⇒ Array<TitleValue>
Individual values in different languages/scripts composing this title.
-
#to_s ⇒ String?
The string representation of the title, for display.
-
#translated_value ⇒ TitleValue?
The translated version of the title, if any.
-
#transliterated_value ⇒ TitleValue?
The transliterated version of the title, if any.
-
#type ⇒ String?
Type of the title, e.g.
-
#type? ⇒ Boolean
Does this title have a type?.
Constructor Details
#initialize(cocina, part_label: nil, part_numbers: nil) ⇒ Title
Create a new Title object.
20 21 22 23 24 |
# File 'lib/cocina_display/titles/title.rb', line 20 def initialize(cocina, part_label: nil, part_numbers: nil) @cocina = cocina @part_label = part_label @part_numbers = part_numbers end |
Instance Attribute Details
#cocina ⇒ Object (readonly)
The underlying Cocina hash.
6 7 8 |
# File 'lib/cocina_display/titles/title.rb', line 6 def cocina @cocina end |
#status ⇒ String?
Status of the title, e.g. “primary”.
10 11 12 |
# File 'lib/cocina_display/titles/title.rb', line 10 def status @status end |
Instance Method Details
#has_translation? ⇒ Boolean
Is there a translated version of the title?
78 79 80 |
# File 'lib/cocina_display/titles/title.rb', line 78 def has_translation? translated_value.present? end |
#has_transliteration? ⇒ Boolean
Is there a transliterated version of the title?
90 91 92 |
# File 'lib/cocina_display/titles/title.rb', line 90 def has_transliteration? transliterated_value.present? end |
#label ⇒ String
Label used when displaying the title.
28 29 30 |
# File 'lib/cocina_display/titles/title.rb', line 28 def label cocina["displayLabel"].presence || type_label end |
#main_value ⇒ TitleValue
The main value of the title, ignoring parallel values if any. If no value is marked as parallel, returns the first value.
60 61 62 |
# File 'lib/cocina_display/titles/title.rb', line 60 def main_value title_values.find(&:main_value?) || title_values.first end |
#parallel_values ⇒ Array<TitleValue>
All values except the main value.
66 67 68 |
# File 'lib/cocina_display/titles/title.rb', line 66 def parallel_values title_values.reject { |value| value.to_s == main_value.to_s } end |
#primary? ⇒ Boolean
Is this marked as a primary title?
47 48 49 |
# File 'lib/cocina_display/titles/title.rb', line 47 def primary? status == "primary" end |
#title_values ⇒ Array<TitleValue>
Individual values in different languages/scripts composing this title.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/cocina_display/titles/title.rb', line 96 def title_values @title_values ||= begin # Create TitleValue objects for all parallelValue nodes or just value if none values = (Array(cocina["parallelValue"]).presence || [cocina]).map do |node| TitleValue.new(node, part_label: @part_label, part_numbers: @part_numbers) end # If there's only one value, we're done return values if values.one? # Set the type of the parallel values to either their sibling main value's type # or the parent title's type. main_type = values.find(&:main_value?)&.type || cocina["type"].presence values.each { |value| value.type ||= main_type } values end end |
#to_s ⇒ String?
The string representation of the title, for display.
53 54 55 |
# File 'lib/cocina_display/titles/title.rb', line 53 def to_s display_title end |
#translated_value ⇒ TitleValue?
The translated version of the title, if any.
72 73 74 |
# File 'lib/cocina_display/titles/title.rb', line 72 def translated_value title_values.find(&:translated?) end |
#transliterated_value ⇒ TitleValue?
The transliterated version of the title, if any.
84 85 86 |
# File 'lib/cocina_display/titles/title.rb', line 84 def transliterated_value title_values.find(&:transliterated?) end |
#type ⇒ String?
Type of the title, e.g. “uniform”, “alternative”, etc.
35 36 37 |
# File 'lib/cocina_display/titles/title.rb', line 35 def type cocina["type"].presence || main_value.type end |
#type? ⇒ Boolean
Does this title have a type?
41 42 43 |
# File 'lib/cocina_display/titles/title.rb', line 41 def type? type.present? end |