Class: CocinaDisplay::Titles::TitleValue

Inherits:
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 ParallelValue

ParallelValue::PARALLEL_TYPES

Instance Attribute Summary

Attributes inherited from ParallelValue

#cocina, #role, #type

Instance Method Summary collapse

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.

Parameters:

  • cocina (Hash)
  • part_label (String, nil) (defaults to: nil)

    part label for digital serials

  • part_numbers (Array<String>) (defaults to: nil)

    part numbers for related resources



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

Note:

This corresponds to the entire MARC 245 field.

The long form of the title, without trailing punctuation.

Returns:

  • (String, nil)


51
52
53
# File 'lib/cocina_display/titles/title_value.rb', line 51

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)


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

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

#labelString?

Custom label used when displaying the title, if any.

Returns:

  • (String, nil)


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

def label
  cocina["displayLabel"].presence || 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)


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

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)


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

The string representation of the title, for display.

Returns:

  • (String, nil)

See Also:



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

def to_s
  display_title
end