Class: CocinaDisplay::Titles::TitleValue
- Inherits:
-
ParallelValue
- Object
- ParallelValue
- CocinaDisplay::Titles::TitleValue
- Defined in:
- lib/cocina_display/titles/title_value.rb
Overview
A Title associated with an item in a single language.
Constant Summary collapse
- PART_TYPES =
Part types for structured titles.
["main title", "nonsorting characters", "part name", "part number", "subtitle"].freeze
Constants inherited from ParallelValue
Instance Attribute Summary
Attributes inherited from ParallelValue
Instance Method Summary collapse
-
#display_title ⇒ String?
The long form of the title, without trailing punctuation.
-
#full_title ⇒ String?
The long form of the title, including subtitle, part name, etc.
-
#initialize(cocina, part_label: nil, part_numbers: nil) ⇒ TitleValue
constructor
Create a new TitleValue object.
-
#label ⇒ String?
Custom label used when displaying the title, if any.
-
#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.
Methods inherited from ParallelValue
#language, #main_value?, #translated?, #transliterated?, #type?
Constructor Details
#initialize(cocina, part_label: nil, part_numbers: nil) ⇒ TitleValue
Create a new TitleValue object.
13 14 15 16 17 |
# File 'lib/cocina_display/titles/title_value.rb', line 13 def initialize(cocina, part_label: nil, part_numbers: nil) super(cocina) @part_label = part_label @part_numbers = part_numbers end |
Instance Method Details
#display_title ⇒ String?
This corresponds to the entire MARC 245 field.
The long form of the title, without trailing punctuation.
51 52 53 |
# File 'lib/cocina_display/titles/title_value.rb', line 51 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.
44 45 46 |
# File 'lib/cocina_display/titles/title_value.rb', line 44 def full_title full_title_str.presence || cocina["value"] end |
#label ⇒ String?
Custom label used when displaying the title, if any.
21 22 23 |
# File 'lib/cocina_display/titles/title_value.rb', line 21 def label cocina["displayLabel"].presence || type_label 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.
36 37 38 |
# File 'lib/cocina_display/titles/title_value.rb', line 36 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.
59 60 61 62 63 64 65 66 67 |
# File 'lib/cocina_display/titles/title_value.rb', line 59 def sort_title return "\u{10FFFF}" unless full_title full_title[nonsorting_chars_str.length..] .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.
28 29 30 |
# File 'lib/cocina_display/titles/title_value.rb', line 28 def to_s display_title end |