Class: CocinaDisplay::Title
- Inherits:
-
Object
- Object
- CocinaDisplay::Title
- Defined in:
- lib/cocina_display/title.rb
Overview
A group of related TitleValues associated with an item.
Instance Attribute Summary collapse
-
#cocina ⇒ Object
readonly
The underlying Cocina hash.
-
#status ⇒ String?
Status of the title, e.g.
-
#type ⇒ String?
Type of the title, e.g.
Instance Method Summary collapse
-
#display_title ⇒ String?
The long form of the title, with added punctuation between parts if not present.
-
#full_title ⇒ String?
The long form of the title, including subtitle, part name, etc.
-
#initialize(cocina, part_label: nil, part_numbers: nil) ⇒ Title
constructor
Create a new Title object.
-
#label ⇒ String
Label used when displaying the title.
-
#primary? ⇒ Boolean
Is this marked as a primary title?.
-
#short_title ⇒ String?
The short form of the title, without subtitle, part name, etc.
-
#sort_title ⇒ String
A string value for sorting by title.
-
#to_s ⇒ String?
The string representation of the title, for display.
-
#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 25 26 |
# File 'lib/cocina_display/title.rb', line 20 def initialize(cocina, part_label: nil, part_numbers: nil) @cocina = cocina @part_label = part_label @part_numbers = part_numbers @type = cocina["type"].presence @status = cocina["status"].presence end |
Instance Attribute Details
#cocina ⇒ Object (readonly)
The underlying Cocina hash.
5 6 7 |
# File 'lib/cocina_display/title.rb', line 5 def cocina @cocina end |
#status ⇒ String?
Status of the title, e.g. “primary”.
14 15 16 |
# File 'lib/cocina_display/title.rb', line 14 def status @status end |
#type ⇒ String?
Type of the title, e.g. “uniform”, “alternative”, etc.
10 11 12 |
# File 'lib/cocina_display/title.rb', line 10 def type @type end |
Instance Method Details
#display_title ⇒ String?
This corresponds to the entire MARC 245 field.
The long form of the title, with added punctuation between parts if not present.
73 74 75 |
# File 'lib/cocina_display/title.rb', line 73 def display_title display_title_str.presence || cocina["value"] end |
#full_title ⇒ String?
This corresponds to the entire MARC 245 field.
The long form of the title, including subtitle, part name, etc.
65 66 67 |
# File 'lib/cocina_display/title.rb', line 65 def full_title full_title_str.presence || cocina["value"] end |
#label ⇒ String
Label used when displaying the title.
30 31 32 |
# File 'lib/cocina_display/title.rb', line 30 def label cocina["displayLabel"].presence || type_label end |
#primary? ⇒ Boolean
Is this marked as a primary title?
42 43 44 |
# File 'lib/cocina_display/title.rb', line 42 def primary? status == "primary" end |
#short_title ⇒ String?
This corresponds to the “short title” in MODS XML, or MARC 245$a only.
The short form of the title, without subtitle, part name, etc.
57 58 59 |
# File 'lib/cocina_display/title.rb', line 57 def short_title short_title_str.presence || cocina["value"] end |
#sort_title ⇒ String
A string value for sorting by title. Ignores punctuation, leading/trailing spaces, and non-sorting characters. If no title is present, returns a high Unicode value so it sorts last.
81 82 83 84 85 86 87 88 89 |
# File 'lib/cocina_display/title.rb', line 81 def sort_title return "\u{10FFFF}" unless full_title full_title[nonsorting_char_count..] .unicode_normalize(:nfd) # Prevent accents being stripped .gsub(/[[:punct:]]*/, "") .gsub(/\W{2,}/, " ") # Collapse whitespace after removing punctuation .strip end |
#to_s ⇒ String?
The string representation of the title, for display.
49 50 51 |
# File 'lib/cocina_display/title.rb', line 49 def to_s display_title end |
#type? ⇒ Boolean
Does this title have a type?
36 37 38 |
# File 'lib/cocina_display/title.rb', line 36 def type? type.present? end |