Class: ModsDisplay::RelatedItem::ValueRenderer

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

Overview

this class provides html markup and is mimicking the same class

in NestedRelatedItem (which is subclassed in purl application)

Instance Method Summary collapse

Constructor Details

#initialize(related_item_element) ⇒ ValueRenderer

Returns a new instance of ValueRenderer.



31
32
33
# File 'lib/mods_display/fields/related_item.rb', line 31

def initialize(related_item_element)
  @related_item_element = related_item_element
end

Instance Method Details

#renderObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mods_display/fields/related_item.rb', line 35

def render
  if related_item_element.location?
    element_text(related_item_element.location_nodeset)
  elsif related_item_element.reference?
    reference_title(related_item_element)
  elsif related_item_element.titleInfo_nodeset.any?
    title = element_text(related_item_element.titleInfo_nodeset)
    location = nil
    location = element_text(related_item_element.location_url_nodeset) if related_item_element.location_url_nodeset.length.positive?

    return if title.empty?

    if location
      "<a href='#{location}'>#{title}</a>".html_safe
    else
      title
    end
  elsif related_item_element.note_nodeset.any?
    citation = related_item_element.note_nodeset.find { |note| note['type'] == 'preferred citation' }

    element_text(citation) if citation
  end
end