Class: CocinaDisplay::Title

Inherits:
Object
  • Object
show all
Defined in:
lib/cocina_display/title.rb

Overview

A group of related TitleValues associated with an item.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cocina, part_label: nil, part_numbers: nil) ⇒ Title

Create a new Title 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



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

#cocinaObject (readonly)

The underlying Cocina hash.



5
6
7
# File 'lib/cocina_display/title.rb', line 5

def cocina
  @cocina
end

#statusString?

Status of the title, e.g. “primary”.

Returns:

  • (String, nil)


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

def status
  @status
end

#typeString?

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

Note:

This corresponds to the entire MARC 245 field.

The long form of the title, with added punctuation between parts if not present.

Examples:

“M. de Courville : [estampe]”

Returns:

  • (String, nil)


73
74
75
# File 'lib/cocina_display/title.rb', line 73

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)


65
66
67
# File 'lib/cocina_display/title.rb', line 65

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

#labelString

Label used when displaying the title.

Returns:

  • (String)


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?

Returns:

  • (Boolean)


42
43
44
# File 'lib/cocina_display/title.rb', line 42

def primary?
  status == "primary"
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)


57
58
59
# File 'lib/cocina_display/title.rb', line 57

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)


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

The string representation of the title, for display.

Returns:

  • (String, nil)

See Also:



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?

Returns:

  • (Boolean)


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

def type?
  type.present?
end