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 main value of 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.
-
#primary_title ⇒ Title?
The first title marked primary, or the first without a type.
-
#secondary_titles ⇒ Array<Title>
All titles except the primary title.
-
#short_title ⇒ String?
The short title for the object, without subtitle, part name, etc.
-
#sort_title ⇒ String
A string value for sorting by title that sorts missing values last.
-
#title_display_data(exclude_primary: false) ⇒ Array<DisplayData>
All TitleValue objects, grouped by their label for display.
Instance Method Details
#additional_titles ⇒ Array<String>
Any additional titles for the object excluding the main value of the primary title. Includes parallel titles of the primary title and all titles from secondary titles.
41 42 43 44 |
# File 'lib/cocina_display/concerns/titles.rb', line 41 def additional_titles (Array(primary_title&.parallel_values) + secondary_titles.flat_map(&:title_values)) .map(&:display_title).compact_blank end |
#all_titles ⇒ Array<Title>
All Title objects built from the Cocina titles.
69 70 71 72 73 74 75 76 77 |
# File 'lib/cocina_display/concerns/titles.rb', line 69 def all_titles @all_titles ||= cocina_titles.map do |cocina_title| CocinaDisplay::Titles::Title.new( cocina_title, part_label: part_label, part_numbers: part_numbers ) 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 |
#primary_title ⇒ Title?
The first title marked primary, or the first without a type.
57 58 59 |
# File 'lib/cocina_display/concerns/titles.rb', line 57 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.
63 64 65 |
# File 'lib/cocina_display/concerns/titles.rb', line 63 def secondary_titles all_titles - [primary_title] end |
#short_title ⇒ String?
The short 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 short_title primary_title&.short_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(exclude_primary: false) ⇒ Array<DisplayData>
All primary titles are included under “Title”, not just the first.
All TitleValue objects, grouped by their label for display.
50 51 52 53 |
# File 'lib/cocina_display/concerns/titles.rb', line 50 def title_display_data(exclude_primary: false) target_titles = exclude_primary ? secondary_titles : all_titles DisplayData.from_objects(target_titles.flat_map(&:title_values)) end |