Class: ModsDisplay::HTML

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

Constant Summary collapse

MODS_DISPLAY_FIELD_MAPPING =
{
  title: :title_info,
  subTitle: :title_info,
  name: :plain_name,
  resourceType: :typeOfResource,
  genre: :genre,
  form: :physical_description,
  extent: :physical_description,
  geo: :extension,
  imprint: :origin_info,
  language: :language,
  description: :physical_description,
  cartographics: :subject,
  abstract: :abstract,
  contents: :tableOfContents,
  audience: :targetAudience,
  note: :note,
  contact: :note,
  collection: :related_item,
  nestedRelatedItem: :related_item,
  relatedItem: :related_item,
  subject: :subject,
  identifier: :identifier,
  location: :location,
  accessCondition: :accessCondition
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ HTML



32
33
34
35
# File 'lib/mods_display/html.rb', line 32

def initialize(xml)
  @stanford_mods = xml
  @xml = xml.mods_ng_xml
end

Instance Method Details

#body(view_context = ApplicationController.renderer) ⇒ Object

Need to figure out how to get the 1st title out of the list. Maybe have a separate class that will omit the first title natively and replace the first key in the the fields list with that.



49
50
51
# File 'lib/mods_display/html.rb', line 49

def body(view_context = ApplicationController.renderer)
  view_context.render ModsDisplay::RecordComponent.new(record: self), layout: false
end

#mods_field(key) ⇒ Object

Raises:

  • (ArgumentError)


70
71
72
73
74
75
# File 'lib/mods_display/html.rb', line 70

def mods_field(key)
  raise ArgumentError unless MODS_DISPLAY_FIELD_MAPPING[key] && @xml.respond_to?(MODS_DISPLAY_FIELD_MAPPING[key])

  field = @xml.public_send(MODS_DISPLAY_FIELD_MAPPING[key])
  mods_field_class(key).new(field)
end

#render_in(view_context) ⇒ Object



42
43
44
# File 'lib/mods_display/html.rb', line 42

def render_in(view_context)
  body(view_context)
end

#titleObject



37
38
39
40
# File 'lib/mods_display/html.rb', line 37

def title
  title_fields = mods_field(:title).fields
  title_fields.empty? ? '' : title_fields.first.values
end

#to_html(view_context = ApplicationController.renderer) ⇒ Object

Deprecated.


54
55
56
57
# File 'lib/mods_display/html.rb', line 54

def to_html(view_context = ApplicationController.renderer)
  fields = [:title] + ModsDisplay::RecordComponent::DEFAULT_FIELDS - [:subTitle]
  view_context.render ModsDisplay::RecordComponent.new(record: self, fields: fields), layout: false
end