Class: CocinaDisplay::Events::Note

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

Overview

A single note represented in a Cocina event, like an issuance or edition note.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cocina) ⇒ Note

Initialize a Note object with Cocina structured data.

Parameters:

  • cocina (Hash)

    The Cocina structured data for the note.



9
10
11
# File 'lib/cocina_display/events/note.rb', line 9

def initialize(cocina)
  @cocina = cocina
end

Instance Attribute Details

#cocinaObject (readonly)

Returns the value of attribute cocina.



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

def cocina
  @cocina
end

Instance Method Details

#labelString

The display label for the note.

Returns:

  • (String)


39
40
41
42
# File 'lib/cocina_display/events/note.rb', line 39

def label
  cocina["displayLabel"].presence ||
    I18n.t(type&.parameterize&.underscore, default: :default, scope: "cocina_display.field_label.event.note")
end

#to_sString?

Note:

Issuance and frequency notes are lowercased for consistency.

Contents of the note.

Returns:

  • (String, nil)


16
17
18
19
20
21
22
23
# File 'lib/cocina_display/events/note.rb', line 16

def to_s
  case type
  when "issuance", "frequency"
    value&.downcase
  else
    value
  end
end

#typeString?

The type of the note, like “issuance” or “edition”.

Returns:

  • (String, nil)


33
34
35
# File 'lib/cocina_display/events/note.rb', line 33

def type
  cocina["type"].presence
end

#valueString?

The contents of the note.

Returns:

  • (String, nil)


27
28
29
# File 'lib/cocina_display/events/note.rb', line 27

def value
  cocina["value"].presence
end