Class: CocinaDisplay::Notes::NoteValue
- Inherits:
-
Parallel::ParallelValue
- Object
- Parallel::ParallelValue
- CocinaDisplay::Notes::NoteValue
- Defined in:
- lib/cocina_display/notes/note_value.rb
Overview
A Note associated with an item in a single language.
Constant Summary collapse
- ABSTRACT_TYPES =
["summary", "abstract", "scope and content"].freeze
- ABSTRACT_DISPLAY_LABEL_REGEX =
/Abstract|Summary|Scope and content/i- PREFERRED_CITATION_TYPES =
["preferred citation"].freeze
- PREFERRED_CITATION_DISPLAY_LABEL_REGEX =
/Preferred citation/i- TOC_TYPES =
["table of contents"].freeze
- TOC_DISPLAY_LABEL_REGEX =
/Table of contents/i
Constants inherited from Parallel::ParallelValue
Parallel::ParallelValue::PARALLEL_TYPES
Instance Attribute Summary
Attributes inherited from Parallel::ParallelValue
Instance Method Summary collapse
-
#abstract? ⇒ Boolean
Check if the note is an abstract.
-
#delimited? ⇒ Boolean
Does this note use a delimiter?.
-
#delimiter ⇒ String?
Delimiter used to join multiple values for display.
-
#flat_value ⇒ String?
Single concatenated string value for the note.
-
#general_note? ⇒ Boolean
Check if the note is a general note (not a table of contents, abstract, preferred citation, or part).
-
#label ⇒ String?
Custom label used when displaying the note, if any.
-
#part? ⇒ Boolean
Check if the note is a part note.
-
#preferred_citation? ⇒ Boolean
Check if the note is a preferred citation.
-
#table_of_contents? ⇒ Boolean
Check if the note is a table of contents.
-
#to_s ⇒ String?
The value to use for display.
-
#values ⇒ Array<String>
The raw values from the Cocina data, flattened if nested.
-
#values_by_type ⇒ Hash{String => Array<String>}
The raw values from the Cocina data as a hash with type as key.
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
#abstract? ⇒ Boolean
Check if the note is an abstract
38 39 40 41 |
# File 'lib/cocina_display/notes/note_value.rb', line 38 def abstract? display_label&.match?(ABSTRACT_DISPLAY_LABEL_REGEX) || ABSTRACT_TYPES.include?(type) end |
#delimited? ⇒ Boolean
Does this note use a delimiter?
32 33 34 |
# File 'lib/cocina_display/notes/note_value.rb', line 32 def delimited? delimiter.present? end |
#delimiter ⇒ String?
Delimiter used to join multiple values for display.
26 27 28 |
# File 'lib/cocina_display/notes/note_value.rb', line 26 def delimiter " -- " if table_of_contents? end |
#flat_value ⇒ String?
Single concatenated string value for the note.
72 73 74 |
# File 'lib/cocina_display/notes/note_value.rb', line 72 def flat_value Utils.compact_and_join(values, delimiter: delimiter || "").presence end |
#general_note? ⇒ Boolean
Check if the note is a general note (not a table of contents, abstract, preferred citation, or part)
45 46 47 |
# File 'lib/cocina_display/notes/note_value.rb', line 45 def general_note? !table_of_contents? && !abstract? && !preferred_citation? && !part? end |
#label ⇒ String?
Custom label used when displaying the note, if any.
14 15 16 |
# File 'lib/cocina_display/notes/note_value.rb', line 14 def label display_label || type_label end |
#part? ⇒ Boolean
These are combined with the title and not displayed separately.
Check if the note is a part note
66 67 68 |
# File 'lib/cocina_display/notes/note_value.rb', line 66 def part? type == "part" end |
#preferred_citation? ⇒ Boolean
Check if the note is a preferred citation
51 52 53 54 |
# File 'lib/cocina_display/notes/note_value.rb', line 51 def preferred_citation? display_label&.match?(PREFERRED_CITATION_DISPLAY_LABEL_REGEX) || PREFERRED_CITATION_TYPES.include?(type) end |
#table_of_contents? ⇒ Boolean
Check if the note is a table of contents
58 59 60 61 |
# File 'lib/cocina_display/notes/note_value.rb', line 58 def table_of_contents? display_label&.match?(TOC_DISPLAY_LABEL_REGEX) || TOC_TYPES.include?(type) end |
#to_s ⇒ String?
The value to use for display.
20 21 22 |
# File 'lib/cocina_display/notes/note_value.rb', line 20 def to_s flat_value end |
#values ⇒ Array<String>
The raw values from the Cocina data, flattened if nested. Strips excess whitespace and the delimiter if present. Splits on the delimiter if it was already included in the values(s).
80 81 82 83 84 85 86 |
# File 'lib/cocina_display/notes/note_value.rb', line 80 def values Utils.flatten_nested_values(cocina).pluck("value") .map { |value| cleaned_value(value) } .flat_map { |value| delimited? ? value.split(delimiter.strip) : [value] } .map(&:strip) .compact_blank end |
#values_by_type ⇒ Hash{String => Array<String>}
The raw values from the Cocina data as a hash with type as key. Strips excess whitespace and the delimiter if present. Splits on the delimiter if it was already included in the values(s).
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cocina_display/notes/note_value.rb', line 92 def values_by_type Utils.flatten_nested_values(cocina).each_with_object({}) do |node, hash| value = cleaned_value(node["value"]) (delimited? ? value.split(delimiter.strip) : [value]).each do |part| type = node["type"] hash[type] ||= [] hash[type] << part.strip end end end |