Class: CocinaDisplay::Titles::TitleValue

Inherits:
Parallel::ParallelValue show all
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 Parallel::ParallelValue

Parallel::ParallelValue::PARALLEL_TYPES

Instance Attribute Summary

Attributes inherited from Parallel::ParallelValue

#cocina, #parent, #role

Instance Method Summary collapse

Methods inherited from Parallel::ParallelValue

#display?, #initialize, #language, #main_value, #own_type, #own_typed?, #primary?, #siblings, #status, #translated?, #transliterated?, #type, #typed?, #vernacular?

Constructor Details

This class inherits a constructor from CocinaDisplay::Parallel::ParallelValue

Instance Method Details

#display_titleString?

Note:

This corresponds to the entire MARC 245 field.

The long form of the title, without trailing punctuation.

Returns:

  • (String, nil)


44
45
46
# File 'lib/cocina_display/titles/title_value.rb', line 44

def display_title
  display_title_str.presence || cocina["value"]
end

#full_titleString?

Note:

This corresponds to the entire MARC 245 field.

The long form of the title, including subtitle, part name, etc.

Examples:

“M. de Courville : [estampe]”

Returns:

  • (String, nil)


37
38
39
# File 'lib/cocina_display/titles/title_value.rb', line 37

def full_title
  full_title_str.presence || cocina["value"]
end

#labelString?

Custom label used when displaying the title, if any.

Returns:

  • (String, nil)


14
15
16
# File 'lib/cocina_display/titles/title_value.rb', line 14

def label
  display_label || type_label
end

#short_titleString?

Note:

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.

Examples:

“M. de Courville”

Returns:

  • (String, nil)


29
30
31
# File 'lib/cocina_display/titles/title_value.rb', line 29

def short_title
  short_title_str.presence || cocina["value"]
end

#sort_titleString

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.

Returns:

  • (String)


52
53
54
55
56
57
58
59
60
# File 'lib/cocina_display/titles/title_value.rb', line 52

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

The string representation of the title, for display.

Returns:

  • (String, nil)

See Also:



21
22
23
# File 'lib/cocina_display/titles/title_value.rb', line 21

def to_s
  display_title
end