Class: ModsDisplay::Field

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

Overview

superclass for processing stanford-mods elements into ModsDisplay::Values retrieved by the fields method

by consuming applications.

Instance Method Summary collapse

Constructor Details

#initialize(stanford_mods_elements) ⇒ Field

per ModsDisplay::HTML::MODS_DISPLAY_FIELD_MAPPING



9
10
11
# File 'lib/mods_display/fields/field.rb', line 9

def initialize(stanford_mods_elements)
  @stanford_mods_elements = stanford_mods_elements
end

Instance Method Details

#fieldsObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/mods_display/fields/field.rb', line 13

def fields
  return_fields = @stanford_mods_elements.map do |stanford_mods_element|
    ModsDisplay::Values.new(
      label: displayLabel(stanford_mods_element) || label,
      values: [element_text(stanford_mods_element)],
      field: self
    )
  end
  collapse_fields(return_fields)
end

#labelObject



24
25
26
27
28
# File 'lib/mods_display/fields/field.rb', line 24

def label
  return nil if @stanford_mods_elements.nil?

  displayLabel(@stanford_mods_elements.first)
end

#render_in(view_context) ⇒ Object



34
35
36
# File 'lib/mods_display/fields/field.rb', line 34

def render_in(view_context)
  to_html(view_context)
end

#to_html(view_context = ApplicationController.renderer) ⇒ Object



30
31
32
# File 'lib/mods_display/fields/field.rb', line 30

def to_html(view_context = ApplicationController.renderer)
  view_context.render ModsDisplay::FieldComponent.with_collection(fields, delimiter: delimiter), layout: false
end