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,
  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.



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

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

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



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

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.



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

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)


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

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



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

def render_in(view_context)
  body(view_context)
end

#titleObject



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

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

#to_html(view_context = ApplicationController.renderer) ⇒ Object

Deprecated.


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

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