Skip to content

Instantly share code, notes, and snippets.

@helrond
Created March 5, 2015 21:45
Show Gist options
  • Save helrond/3082b1ebc42693cb5d1f to your computer and use it in GitHub Desktop.
Save helrond/3082b1ebc42693cb5d1f to your computer and use it in GitHub Desktop.
class MODSSerializer < ASpaceExport::Serializer
serializer_for :mods
include JSONModel
def serialize_mods_inner(mods, xml)
xml.titleInfo {
xml.title mods.title
}
xml.typeOfResource mods.type_of_resource
xml.language {
xml.languageTerm(:type => 'code') {
xml.text mods.language_term
}
}
xml.physicalDescription{
mods.extents.each do |extent|
xml.extent extent
end
}
mods.notes.each do |note|
if note.wrapping_tag
xml.send(note.wrapping_tag) {
serialize_note(note, xml)
}
else
serialize_note(note, xml)
end
end
mods.subjects.each do |subject|
xml.subject(:authority => subject['source']) {
subject['terms'].each do |term|
xml.topic term
end
}
end
mods.names.each do |name|
case name['role']
when 'subject'
xml.subject {
serialize_name(name, xml)
}
else
serialize_name(name, xml)
end
end
mods.parts.each do |part|
xml.part(:ID => part['id']) {
xml.detail {
xml.title part['title']
}
}
end
# flattened tree
mods.each_related_item do |item|
xml.relatedItem(:type => 'constituent') {
serialize_mods_inner(item, xml)
}
end
xml.relatedItem(:type => 'host') {
xml.name mods.resource
}
end
end
class MODSModel < ASpaceExport::ExportModel
model_for :mods
include JSONModel
attr_accessor :resource
@archival_object_map = {
:title => :title=,
:language => :language_term=,
:extents => :handle_extent,
:subjects => :handle_subjects,
:linked_agents => :handle_agents,
:notes => :handle_notes,
:linked_instances => :handle_instances,
}
def initialize
@extents = []
@notes = []
@subjects = []
@names = []
@parts = []
@resource =[]
end
def handle_instances(linked_instances)
linked_instances.each do |link|
component = link['_resolved']
self.resource << {
'title' => component['title']
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment