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

Instance Method Details

#additional_titlesArray<String>

Any additional titles for the object excluding the primary title.

Returns:

  • (Array<String>)

See Also:



40
41
42
# File 'lib/cocina_display/concerns/titles.rb', line 40

def additional_titles
  secondary_titles.map(&:display_title).compact_blank
end

#all_titlesArray<Title>

All Title objects built from the Cocina titles. Flattens parallel values into separate titles.

Returns:



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

The full title, joined together with additional punctuation. If there are multiple primary titles, uses the first.

Returns:

  • (String, nil)

See Also:



25
26
27
# File 'lib/cocina_display/concerns/titles.rb', line 25

def display_title
  primary_title&.display_title
end

#full_titleString?

The full title for the object, including subtitle, part name, etc. If there are multiple primary titles, uses the first.

Returns:

  • (String, nil)

See Also:



17
18
19
# File 'lib/cocina_display/concerns/titles.rb', line 17

def full_title
  primary_title&.full_title
end

#main_titleString?

The main title for the object, without subtitle, part name, etc. If there are multiple primary titles, uses the first.

Returns:

  • (String, nil)

See Also:

  • Title#main_title


9
10
11
# File 'lib/cocina_display/concerns/titles.rb', line 9

def main_title
  primary_title&.short_title
end

#primary_titleArray<Title>

The first title marked primary, or the first without a type.

Returns:



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_titlesArray<Title>

All titles except the primary title.

Returns:



59
60
61
# File 'lib/cocina_display/concerns/titles.rb', line 59

def secondary_titles
  all_titles - [primary_title]
end

#sort_titleString

A string value for sorting by title that sorts missing values last. If there are multiple primary titles, uses the first.

Returns:

  • (String)

See Also:



33
34
35
# File 'lib/cocina_display/concerns/titles.rb', line 33

def sort_title
  primary_title&.sort_title || "\u{10FFFF}"
end

#title_display_dataArray<DisplayData>

Note:

All primary titles are included under “Title”, not just the first.

All Title objects, grouped by their label for display.

Returns:



47
48
49
# File 'lib/cocina_display/concerns/titles.rb', line 47

def title_display_data
  DisplayData.from_objects(all_titles)
end