Class: ModsDisplay::RelatedItem::ValueRenderer

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

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ ValueRenderer

Returns a new instance of ValueRenderer.



27
28
29
# File 'lib/mods_display/fields/related_item.rb', line 27

def initialize(value)
  @value = value
end

Instance Method Details

#renderObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mods_display/fields/related_item.rb', line 31

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

    return if title.empty?

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

    element_text(citation) if citation
  end
end