Class: ModsDisplay::RelatedItem

Inherits:
Field
  • Object
show all
Includes:
RelatedItemConcerns
Defined in:
lib/mods_display/fields/related_item.rb

Defined Under Namespace

Classes: ValueRenderer

Instance Method Summary collapse

Methods inherited from Field

#label, #render_in, #to_html

Constructor Details

#initialize(related_item_elements, value_renderer: ValueRenderer) ⇒ RelatedItem

Returns a new instance of RelatedItem.



7
8
9
10
# File 'lib/mods_display/fields/related_item.rb', line 7

def initialize(related_item_elements, value_renderer: ValueRenderer)
  super(related_item_elements)
  @value_renderer = value_renderer
end

Instance Method Details

#fieldsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mods_display/fields/related_item.rb', line 12

def fields
  return_fields = RelatedItemValue.for_stanford_mods_elements(@stanford_mods_elements).map do |related_item_element|
    next if related_item_element.collection?
    next if render_nested_related_item?(related_item_element)

    text = @value_renderer.new(related_item_element).render
    next if text.nil? || text.empty?

    ModsDisplay::Values.new(
      label: related_item_label(related_item_element),
      values: [text]
    )
  end.compact
  collapse_fields(return_fields)
end