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,
  referenceTitle: :title_info,
  name: :plain_name,
  resourceType: :typeOfResource,
  genre: :genre,
  form: :physical_description,
  extent: :physical_description,
  geo: :extension,
  copyrightDate: :origin_info,
  dateCaptured: :origin_info,
  dateCreated: :origin_info,
  dateIssued: :origin_info,
  dateModified: :origin_info,
  dateOther: :origin_info,
  dateValid: :origin_info,
  edition: :origin_info,
  frequency: :origin_info,
  imprint: :origin_info,
  issuance: :origin_info,
  place: :origin_info,
  publisher: :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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mods) ⇒ HTML

Returns a new instance of HTML.



45
46
47
48
# File 'lib/mods_display/html.rb', line 45

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

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



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

def xml
  @xml
end

Instance Method Details

#body(view_context = ApplicationController.renderer, html_attributes: {}, component: ModsDisplay::RecordComponent) ⇒ 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.



64
65
66
# File 'lib/mods_display/html.rb', line 64

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

#mods_field(key, field_args: {}) ⇒ Object

Raises:

  • (ArgumentError)


85
86
87
88
89
90
# File 'lib/mods_display/html.rb', line 85

def mods_field(key, field_args: {})
  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, **field_args)
end

#render_in(view_context) ⇒ Object



57
58
59
# File 'lib/mods_display/html.rb', line 57

def render_in(view_context)
  body(view_context)
end

#titleObject



52
53
54
55
# File 'lib/mods_display/html.rb', line 52

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

#to_html(view_context = ApplicationController.renderer) ⇒ Object

Deprecated.


69
70
71
72
# File 'lib/mods_display/html.rb', line 69

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