Module: CocinaDisplay::Concerns::Titles
- Included in:
- CocinaDisplay::CocinaRecord, RelatedResource
- Defined in:
- lib/cocina_display/concerns/titles.rb
Overview
Methods for finding and formatting titles.
Instance Method Summary collapse
-
#additional_titles ⇒ Array<String>
Any additional titles for the object excluding the primary title.
-
#all_titles ⇒ Array<Title>
All Title objects built from the Cocina titles.
-
#display_title ⇒ String?
The full title, joined together with additional punctuation.
-
#full_title ⇒ String?
The full title for the object, including subtitle, part name, etc.
-
#main_title ⇒ String?
The main title for the object, without subtitle, part name, etc.
-
#primary_title ⇒ Array<Title>
The first title marked primary, or the first without a type.
-
#secondary_titles ⇒ Array<Title>
All titles except the primary title.
-
#sort_title ⇒ String
A string value for sorting by title that sorts missing values last.
-
#title_display_data ⇒ Array<DisplayData>
All Title objects, grouped by their label for display.
Instance Method Details
#additional_titles ⇒ Array<String>
Any additional titles for the object excluding the primary title.
40 41 42 |
# File 'lib/cocina_display/concerns/titles.rb', line 40 def additional_titles secondary_titles.map(&:display_title).compact_blank end |
#all_titles ⇒ Array<Title>
All Title objects built from the Cocina titles. Flattens parallel values into separate titles.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cocina_display/concerns/titles.rb', line 66 def all_titles @all_titles ||= cocina_titles.flat_map do |cocina_title| (Array(cocina_title["parallelValue"]).presence || [cocina_title]).map do |value| Title.new(value, part_label: part_label, part_numbers: part_numbers).tap do |title| title.type ||= cocina_title["type"] title.status ||= cocina_title["status"] end end end end |
#display_title ⇒ String?
The full title, joined together with additional punctuation. If there are multiple primary titles, uses the first.
25 26 27 |
# File 'lib/cocina_display/concerns/titles.rb', line 25 def display_title primary_title&.display_title end |
#full_title ⇒ String?
The full title for the object, including subtitle, part name, etc. If there are multiple primary titles, uses the first.
17 18 19 |
# File 'lib/cocina_display/concerns/titles.rb', line 17 def full_title primary_title&.full_title end |
#main_title ⇒ String?
The main title for the object, without subtitle, part name, etc. If there are multiple primary titles, uses the first.
9 10 11 |
# File 'lib/cocina_display/concerns/titles.rb', line 9 def main_title primary_title&.short_title end |
#primary_title ⇒ Array<Title>
The first title marked primary, or the first without a type.
53 54 55 |
# File 'lib/cocina_display/concerns/titles.rb', line 53 def primary_title all_titles.find { |title| title.primary? }.presence || all_titles.find { |title| !title.type? } end |
#secondary_titles ⇒ Array<Title>
All titles except the primary title.
59 60 61 |
# File 'lib/cocina_display/concerns/titles.rb', line 59 def secondary_titles all_titles - [primary_title] end |
#sort_title ⇒ String
A string value for sorting by title that sorts missing values last. If there are multiple primary titles, uses the first.
33 34 35 |
# File 'lib/cocina_display/concerns/titles.rb', line 33 def sort_title primary_title&.sort_title || "\u{10FFFF}" end |
#title_display_data ⇒ Array<DisplayData>
All primary titles are included under “Title”, not just the first.
All Title objects, grouped by their label for display.
47 48 49 |
# File 'lib/cocina_display/concerns/titles.rb', line 47 def title_display_data DisplayData.from_objects(all_titles) end |